navigation-properties

Navigation Property not loading when only the ID of the related object is populated

自闭症网瘾萝莉.ら 提交于 2019-11-28 05:31:04
问题 I am trying to establish a many-to-one relationship. The entity that represents the “many” has a navigation property pointing back to the parent entity. It looks like this: public abstract class BaseEntity { /// <summary> /// Key Field for all entities /// </summary> /// [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } /// <summary> /// Date entity was created /// </summary> public DateTime DateCreated { get; set; } /// <summary> /// Last date Modified /

Why Navigation Properties are virtual by default in EF

℡╲_俬逩灬. 提交于 2019-11-27 17:59:13
I have following POCO class being used in EF 6.x. My question : Why is the navigation property of 'Posts' under 'Blog' entity declared as virtual? public class Blog { public int BlogId { get; set; } public string Name { get; set; } public string Url { get; set; } public string Tags { get; set; } public virtual ICollection<Post> Posts { get; set; } } If you define your navigation property virtual , Entity Framework will at runtime create a new class (dynamic proxy) derived from your class and uses it instead of your original class. This new dynamically created class contains logic to load the

EF5 How to get list of navigation properties for a domain object

六眼飞鱼酱① 提交于 2019-11-26 23:24:11
问题 I'm working on an EF 5 Code-First solution and I am trying to update an existing entity with a modified one using the Repository pattern: public void UpdateValues(T originalEntity, T modifiedEntity) { _uow.Context.Entry(originalEntity).CurrentValues.SetValues(modifiedEntity); My simplified domain object looks like this: public class PolicyInformation : DomainObject { //Non-navigation properties public string Description {get;set;} public bool Reinsurance {get;set;} ... //Navigation properties

Entity Framework - Add Navigation Property Manually

不打扰是莪最后的温柔 提交于 2019-11-26 21:23:41
I generated an Entity Framework Model (4.0) from my database. I did not design the database and do not have any control over the schema, but there are a few tables that do not have foreign key constraints defined, but there is an implicit relationship defined. For example: I have a table called People that has the following columns: GenderID RaceID There are tables for both Gender and Race but there is no foreign key in the People table. When I imported the model it did not add Navigation Properties for these relationships. I tried to add it manually but From Role and To Role are disabled. I'm

Why Navigation Properties are virtual by default in EF

蓝咒 提交于 2019-11-26 19:17:58
问题 I have following POCO class being used in EF 6.x. My question : Why is the navigation property of 'Posts' under 'Blog' entity declared as virtual? public class Blog { public int BlogId { get; set; } public string Name { get; set; } public string Url { get; set; } public string Tags { get; set; } public virtual ICollection<Post> Posts { get; set; } } 回答1: If you define your navigation property virtual , Entity Framework will at runtime create a new class (dynamic proxy) derived from your class

navigation property should be virtual - not required in ef core?

本小妞迷上赌 提交于 2019-11-26 09:01:37
问题 As I remember in EF navigation property should be virtual: public class Blog { public int BlogId { get; set; } public string Name { get; set; } public string Url { get; set; } public string Tags { get; set; } public virtual ICollection<Post> Posts { get; set; } } But I look at EF Core and don\'t see it as virtual: public class Student { public int ID { get; set; } public string LastName { get; set; } public string FirstMidName { get; set; } public DateTime EnrollmentDate { get; set; } public

Entity Framework - Add Navigation Property Manually

不打扰是莪最后的温柔 提交于 2019-11-26 07:55:39
问题 I generated an Entity Framework Model (4.0) from my database. I did not design the database and do not have any control over the schema, but there are a few tables that do not have foreign key constraints defined, but there is an implicit relationship defined. For example: I have a table called People that has the following columns: GenderID RaceID There are tables for both Gender and Race but there is no foreign key in the People table. When I imported the model it did not add Navigation

EF codefirst : Should I initialize navigation properties?

a 夏天 提交于 2019-11-26 00:15:43
问题 I had seen some books(e.g programming entity framework code first Julia Lerman ) define their domain classes (POCO) with no initialization of the navigation properties like: public class User { public int Id { get; set; } public string UserName { get; set; } public virtual ICollection<Address> Address { get; set; } public virtual License License { get; set; } } some other books or tools (e.g Entity Framework Power Tools ) when generates POCOs initializes the navigation properties of the the