实体框架中的域类和实体类有什么区别? [英] What is difference between domain class and entity class in entity framework ?

查看:154
本文介绍了实体框架中的域类和实体类有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

了解实体框架的新内容......

实体框架中的域类和实体类有什么区别?





有人可以通过例子说出来吗?



我尝试了什么:



在线资源阅读和学习实体框架无法区分它们

解决方案

通常,域对象定义业务对象及其属性和方法。它用于处理和移动处理系统中的数据。存在Entity对象以获取这些域属性并将它们映射到持久存储对象,例如数据库表。



使用AutoMapper等映射工具可以将域对象映射到Entity对象,也可以根据需要单独编写代码。



在下面的示例中,持久存储是一个名为BookInformation的数据库表,其中包含BookId,Book_Title和Book_ISBN列。

该实体对象在BookEntity类中定义。



域对象类Book定义有3个属性,BookID是一个数据库生成GUID,BookName和ISBN。







  //  域对象 
public class 预订

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid BookId { get ; set ;}
public string BookName { get ; set ;}
public string ISBN { get ; set ;}



// 实体对象
[表( BookInformation )]
public class BookEntity

[Key]
[Column( BookId)]
[DatabaseGenerated (DatabaseGeneratedOption.Identity)]
public Guid BookId { get ; set ;}

[Column( Book_Title)]
public string BookName { get ; set ;}

[Column( Book_ISBN)]
public string ISBN { get ; set ;}


New to learn Entity Framework...

What is Difference between Domain Class and Entity Class in Entity Framework ?



Can Someone tell by example ?

What I have tried:

Reading and Learning Entity Framework by Online Resources by unable to differentiate between them

解决方案

Typically, the domain object defines the business object and it's properties and methods. It's used to manipulate and move the data within the processing system. The Entity object exists to take those domain properties and map them to a persistent storage object, such as a database table.

Using a mapping tool such as AutoMapper will do the mapping of the domain object to the Entity object, or you can code that separately if desired.

In the example below the persistent storage is a database table called BookInformation, which has columns BookId, Book_Title, and Book_ISBN.
That entity object is defined in the class BookEntity.

The domain object class Book is defined with 3 properties, BookID which is a database generated GUID, the BookName and the ISBN.



// Domain object
public class Book
(
	[Key]
	[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
	public Guid BookId {get;set;}
	public string BookName {get;set;}
	public string ISBN {get;set;}
)


// Entity Object
[Table("BookInformation")]
public class BookEntity
(
	[Key]
	[Column("BookId")]
	[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
	public Guid BookId {get;set;}
	
	[Column("Book_Title")]
	public string BookName {get;set;}
	
	[Column("Book_ISBN")]
	public string ISBN {get;set;}

)


这篇关于实体框架中的域类和实体类有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆