- What type would you use for the property that represents a table, for example, the
Products
property of aNorthwind
database context?
Answer:DbSet<T>
, where T
is the entity type, for example, Product
.
- What type would you use for the property that represents a one-to-many relationship, for example, the
Products
property of aCategory
entity?
Answer:ICollection<T>
, where T
is the entity type, for example, Product
.
- What is the EF convention for primary keys?
Answer: The property named ID
or ClassNameID
is assumed to be the primary key. If the type of that property is any of the following, then the property is also marked as being an IDENTITY
column: tinyint
, smallint
, int
, bigint
, guid
.
- When would you use an annotation attribute in an entity class?
Answer: You would use an annotation attribute in an entity class when the conventions cannot work out the correct mapping between the classes and tables. For example, if a class...