tags:

views:

115

answers:

1

What does it actually mean by the term "Entity" in LINQ?

What is the difference between EntitySet and EntityRef when talking about LINQ?

Can you give a real-world example? Like Order and OrderItems, etc?

+1  A: 

In the context of Linq-to-SQL, an Entity basically just means an object that can be stored in the database. Note that the term is sometimes used more narrowly, e.g. in Domain Driven Design.

An EntitySet represents an object's relation to a set of other objects, whereas an EntityRef represents a relation to a single other object. In other words, if you have a many-to-one relationship between two classes of objects, one end will be represented by an EntitySet, and the other by an EntityRef.

Jonas H
Can you give a real-world example? Like Order and OrderItems, etc?
JMSA
Typically your Order class would have a property named Items of type EntitySet<OrderItem>, and your OrderItem class would have a property named Order of type Order. However, internally, the OrderItem class uses a variable of type EntityRef<Order> when implementing the order property. This enables Linq to support deferred loading, i.e. not loading the related object until you access the property.
Jonas H