navigational-properties

What is a correct way to select a property of optional navigation property in Entity Framework?

可紊 提交于 2020-03-25 16:12:52
问题 What is a correct way to select a property of optional navigation property entity framework? I am concerned that in case the navigation property will be null, then the error will be thrown when I try to access its (optional navigation property`s) property. Here is what I tried: return await this.relatedCasesRepository .GetAll() .AsNoTracking() .Where(rc => rc.FirstCaseId == caseId || rc.SecondCaseId == caseId) .Select(rc => new RelatedCaseInfoDto { FirstCaseId = rc.FirstCaseId, FirstCaseName

EntityFramework 4.3.1 Code First Navigation Property Mapping and Visibility

笑着哭i 提交于 2020-01-17 04:06:27
问题 This is a long introduction for a short question, sorry!! I'm working with EF 4.3.1 Code First and I've got the following model public class Action { protected Action() { } public virtual int ActionID { get; protected set; } [Required] [StringLength(DataValidationConstants.NameLength)] public virtual string Name {get; set;} [StringLength(DataValidationConstants.DescriptionLength)] public virtual string Description { get; set; } public virtual ICollection<Role> Roles { get; set; } public

Explicit loading of multiple references/collections on entity

孤人 提交于 2019-12-14 03:46:39
问题 Consider following entity model: public class Parent { public virtual FirstChild FirstChild { get; set; } public virtual SecondChild SecondChild { get; set; } } In my code, I have loaded Parent entity: Parent parent = <loaded in some way>; To explicitly load its navigational properties, I use db.Entry(parent).Reference(p => p.FirstChild).Load(); db.Entry(parent).Reference(p => p.SecondChild).Load(); But this results in two DB queries. Question: is there a more elegant way, that would allow to

EF4 complex type with navigation property (is it possible) or alternatives?

限于喜欢 提交于 2019-11-29 12:23:16
I hit the wall with doing EF4 Model with DB first approach using Linq-to-Entities with POCO... I have two tables: Customer and NamePrefix that are related via NamePrefixId . Columns are: Customer NamePrefix ---------- ---------- CustomerId (PK) NamePrefixId (PK) NamePrefixId (FK) LastName FirstName MiddleInitial .... In this instance the Customer entity has a navigational property NamePrefix . I created a complex type NameOfPerson , so that I can use it in other entities. The complex type consists of NamePrefixId , LastName , FirstName , MiddleInitial . But now I am getting the following error

Problem with Eager Loading Nested Navigation Based on Abstract Entity (EF CTP5)

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 00:26:08
I a portion of my EF model that looks like this: Summary: Location has many Posts Post is an abstract class Discussion derives from Post Discussions have many Comments Now, the query i'm trying to achieve: Get information about Location Id 1234, including any Discussions and Comments associated with those Discussions. I can get discussions and the comments like this: var discussions = ctx.Posts .OfType<Discussion>() .Include(x => x.Comments) .ToList(); But i can't seem to get it based on the Posts navigation on the Location entity. I've tried this: var locationWithDiscussionsAndComments = ctx

EF4 complex type with navigation property (is it possible) or alternatives?

懵懂的女人 提交于 2019-11-28 05:39:10
问题 I hit the wall with doing EF4 Model with DB first approach using Linq-to-Entities with POCO... I have two tables: Customer and NamePrefix that are related via NamePrefixId . Columns are: Customer NamePrefix ---------- ---------- CustomerId (PK) NamePrefixId (PK) NamePrefixId (FK) LastName FirstName MiddleInitial .... In this instance the Customer entity has a navigational property NamePrefix . I created a complex type NameOfPerson , so that I can use it in other entities. The complex type

Problem with Eager Loading Nested Navigation Based on Abstract Entity (EF CTP5)

▼魔方 西西 提交于 2019-11-27 15:18:38
问题 I a portion of my EF model that looks like this: Summary: Location has many Posts Post is an abstract class Discussion derives from Post Discussions have many Comments Now, the query i'm trying to achieve: Get information about Location Id 1234, including any Discussions and Comments associated with those Discussions. I can get discussions and the comments like this: var discussions = ctx.Posts .OfType<Discussion>() .Include(x => x.Comments) .ToList(); But i can't seem to get it based on the