Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
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
Posted
Updated 3-Oct-18 18:56pm
v3

1 solution

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.



C#
// 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;}

)
 
Share this answer
 
Comments
DoingWork 4-Oct-18 1:21am    
Whats the difference between Entity Object and Context Class ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900