navigation-properties

Including navigation properties from Entity Framework TPH classes

做~自己de王妃 提交于 2019-12-03 20:14:00
I've got an EF hierarchy that (dramatically simplified) looks something like this: class Room { EntityCollection<Session> Sessions; } class Session { EntityCollection<Whiteboard> Whiteboards; EntityReference Room; } class Whiteboard { EntityCollection<WhiteboardShape> WhiteboardShapes; EntityReference Session; } abstract class WhiteboardShape { EntityReference Whiteboard; } class WhiteboardShapeEllipse : WhiteboardShape { } class WhiteboardShapePolyline { WhiteboardShape { EntityCollection<PolylinePoint> PolylinePoints } class PolylinePoint { EntityReference<WhiteboardShapePolyline>

load navigation properties with filter for Entity Framework 4.3

淺唱寂寞╮ 提交于 2019-12-02 17:53:31
问题 Few days back I put a question regarding mapping two classes Message and MessageStatusHistory using EF. The mapping is going fine but I am facing some problems with the navigation property StatusHistory in class Message that relates it to MessageStatusHistory objects. I am loading the messages for one user only and want to the statuses pertaining to that user only. Like I would want to show if the user has marked message as read/not-read and when. If I use default loading mechanism like

How can you add a navigation property on a view in EF 6.1 CodeFirst

一笑奈何 提交于 2019-12-01 22:16:08
问题 Let's make a case to explain my problem. MyTable1 +id +myTable2Id MyTable2 +id MyView1 +id +myTable2Id MyView1 exists in the case, from data from the MyTable1. Now i want to create a Navigation property from my EF6.1 Code first approach in my View to MyTable2. I know that it was possible from the database first approach, but is it also possible from the code-first approach and how? EDIT: I search some on internet, but due many meanings of the word View, it's very hard to find information on

Can you exclude reverse navigation properties in EF when eager loading?

百般思念 提交于 2019-12-01 19:20:03
When I use the .Include syntax in EF6, reverse navigation properties are always loaded. Is there a way to turn that off? Here is a sample query. private static IQueryable<Account> GetAccountsEager(this IRepository<Account> repository) { return repository .Queryable() .Include(e => e.AccountLocations .Select(l => l.Address.City.State.Country)); } This gives me the account's collection of AccountLocations. However, the Address' city has this reverse navigation property on it: public virtual ICollection<Address> Addresses { get; set; } ..thus it back-load all the reverse navigation addresses to

How can you add a navigation property on a view in EF 6.1 CodeFirst

こ雲淡風輕ζ 提交于 2019-12-01 18:45:09
Let's make a case to explain my problem. MyTable1 +id +myTable2Id MyTable2 +id MyView1 +id +myTable2Id MyView1 exists in the case, from data from the MyTable1. Now i want to create a Navigation property from my EF6.1 Code first approach in my View to MyTable2. I know that it was possible from the database first approach, but is it also possible from the code-first approach and how? EDIT: I search some on internet, but due many meanings of the word View, it's very hard to find information on it. Also with the approaches in codes that i tried, i always get an error that the migration can't be

Using Entity Framework navigation properties without creating lots of queries (avoiding N+1)

巧了我就是萌 提交于 2019-12-01 10:30:25
I've been using Entity Framework Profiler to test my data access in an MVC project and have come accross several pages where I'm making far more db queries than I need to because of N+1 problems. Here is a simple example to show my problem: var club = this.ActiveClub; // ActiveClub uses code similar to context.Clubs.First() var members = club.Members.ToList(); return View("MembersWithAddress", members); The view loops through Members and then follows a navigion property on each member to also show their address. Each of the address requests results in an extra db query. One way to solve this

Load navigation property from inherited class

好久不见. 提交于 2019-12-01 07:03:55
I want to get all contact entities (including Person -> Employees) Contact |<- Person | |-> Employer | |<- Organization | |-> Employees Person and Organization inherits from Contact. When i use FirstOrDefault my employees and my employer entity were not loaded. public Contact GetContactById(int id) { var contact = GetContacts().FirstOrDefault(c => c.Id == id); return contact; } private IQueryable<Contact> GetContacts() { var contacts = _contextProvider.Context.Contacts .Include("Addresses"); return contacts; } That's my current workaround: public Contact GetContactById(int id) { var contact =

Undelete an entity marked as EntityState.Delete?

匆匆过客 提交于 2019-11-30 14:01:32
instead of talking let me talk with code: Dim Contact = Context.Contacts.Include("Phones") Dim phone = Contact.Phones(0) Contact.Remove(phone) How do I refresh the context now, canceling last relation deletion? I tried: Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation Context.Refresh(RefreshMode.StoreWins, _ ObjectStateManager.GetObjectStateEntries(EntityState.Deleted)) the last one throws an InvalidOperationException: The element at index 0 in the collection of objects to refresh has a null EntityKey property value or is not attached to this ObjectStateManager.

Undelete an entity marked as EntityState.Delete?

不问归期 提交于 2019-11-29 19:57:25
问题 instead of talking let me talk with code: Dim Contact = Context.Contacts.Include("Phones") Dim phone = Contact.Phones(0) Contact.Remove(phone) How do I refresh the context now, canceling last relation deletion? I tried: Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation Context.Refresh(RefreshMode.StoreWins, _ ObjectStateManager.GetObjectStateEntries(EntityState.Deleted)) the last one throws an InvalidOperationException: The element at index 0 in the collection of

Entity Framework - Selective Condition on Included Navigation Property

久未见 提交于 2019-11-28 08:05:44
问题 Assume I have these simplified EF generated entities... public class PurchaseOrder { public int POID {get;set;} public int OrderID {get;set;} public int VendorID {get;set;} public IEnumerable<Order> Orders {get;set;} } public class Order { public int OrderID {get;set;} public decimal Price {get;set;} public IEnumerable<Item> Items {get;set;} } public class Item { public int OrderID {get; set;} public string SKU {get;set;} public int VendorID {get;set;} public Order Order {get;set;} } Business