Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
连接表和C#类?_C#_Oop_Database Design - Fatal编程技术网

连接表和C#类?

连接表和C#类?,c#,oop,database-design,C#,Oop,Database Design,我有ResorceTopices&Resources表m到m的关系和2个表之间的连接。只是想知道我是否应该为连词编写类,以及我是否应该编写一个类似于此代码的类 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace BOL { class Topic_Resorsce { public int Id { get; set; }

我有ResorceTopices&Resources表m到m的关系和2个表之间的连接。只是想知道我是否应该为连词编写类,以及我是否应该编写一个类似于此代码的类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BOL
{
    class Topic_Resorsce
    {
        public int Id { get; set; }
        public int TopicId { get; set; }
        public int ResorsceId { get; set; }
    }
}

显然,你可以随心所欲,但我的答案是否定的。你的课程应该是这样的:

public class Topic { public int Id { get; set; } //whatever other fields should exist public Resource Resource {get; set; } } public class Resource { public int Id { get; set; } //whatever other fields should exist } 公开课主题 { 公共int Id{get;set;} //任何其他领域都应该存在 公共资源资源{get;set;} } 公共类资源 { 公共int Id{get;set;} //任何其他领域都应该存在 } 现在您创建了一个数据访问层(或者更喜欢使用一个ORM,比如EntityFramework(包含在.NET中)、NHibernate、NHydrate、Lightspeed等),它在类和数据库之间映射


当然,有很多代码在SQL表和POCO之间有一对一的映射,所以我不鼓励这样做。

如何从数据库映射到?我使用BOL和ADO.net