-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Make it easier to handle growing models by supporting graph hydration and/or something like MyContext.AllEntities<EntityType>() -- or a better approach you can suggest #3507
Comments
Hey, I may be missing what you are trying to achieve... but you can already have a ~Rowan |
Thanks. Your comment made me rethink this-- and I believe I was fighting the wrong battle. By default/convention when I added a DBSet then BaseType was added to the Model as an EntityType and required a Key. I didn't want this as I assumed it was trying to do TPH. Workaround 1 was to remove the DBSet which is described above which is not ideal Workaround 2 looks like if I go ahead and give BaseType a Key we no longer fail on model creation with the "requires a key" exception. The db it creates looks like TPC, but including BaseType as a table as it if were a concrete type. This isn't ideal as I think the table would always be empty, but not terrible, except see IndexOutOfRangeException paragraph below. Workaround 3 was to remove the EntityType for BaseType from the model by using RemoveEntityType(). This gets us past model creation at runtime, but.... When using workarounds 2 or 3 all runtime calls to MyDbContext.Add() fail with a mysterious IndexOutOfRangeException. Also TrackGraph() appears to be broken (nothing happens). If I can't figure out the IndexOutOfRangeException and TrackGraph behavior I'll post the repro code. I suspect I'm doing something wrong defining the relationships. |
This may be heading in the direction of a separate bug, but I'll continue here for now. For some reason EF7beta8 hates this model. Depending on various choices you can make with the model (see comments) it will always fail (but in different places) with NullReferenceException or IndexOutOfRangeException.
|
Since the issues I'm hitting now are significantly removed from the issue title, I am going to open separate more narrowly scoped issues for those as potential bugs. Thanks. |
In a scenario where a hub & spoke 1:Many domain model grows over time, it becomes cumbersome and fragile to modify the hub entity class with new navigations and modify the dbcontext class with new DBSet properties for every new spoke entity type. For example imagine an extensible model where various devs may add new spoke types (which all derive from... say
SpokeTypeBase
), but the main hub type and dbcontext are expected to be stable.Today this can handled for saving to db with TPC by:
public virtual DBSet<SpokeTypeBase> AllSpokeEntities
on the dbcontext else OnModelCreating will try to create an entity type for SpokeTypeBase and insist on a PK.MyContext.Add(each entity)
While this works for saving to DB, creating a nice TPC layout with correct relationships, it leaves no way that I have found to retrieve spoke entities from the db context.
It would be nice if EF could allow for this pattern by either:
A) Supporting automatic object graph hydration so I only need the hub type exposed as a dbset on the dbcontext, and/or
B) Support something along the lines of
public virtual DBSet<SpokeTypeBase> AllSpokeEntities
on the db context to be used likeMyContext.AllSpokeEntities.OfType()
or some private analog to be exposed likeMyContext.AllSpokeEntities<SpokeType>()
.C) or a better approach to the same problem space that someone else might suggest.
Thanks.
The text was updated successfully, but these errors were encountered: