EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

Support for TPT inheritance type with Entity Framework 6

Open saurabh-shelgaonkar opened this issue 8 years ago • 5 comments

Hi,

Does the framework currently support TPT inheritance with EF6? I have been getting mapping errors when trying to read data from tables which have TPT inheritance.

Does the framework have any plans to implement this support?

Regards, Saurabh

saurabh-shelgaonkar avatar Oct 12 '17 07:10 saurabh-shelgaonkar

Hi,

After much effort and trying different solutions, removing the child classes from DbContext has solved my issue for the time being.

So closing the issue for now.

Regards, Saurabh

saurabh-shelgaonkar avatar Oct 12 '17 08:10 saurabh-shelgaonkar

Hello @saurabh-shelgaonkar ,

Could you let me know where this issue where happening?

We plan to support soon TPC and TPC for Batch Update and Batch Delete, someone already provided us a pull to merge.

Best Regards,

Jonathan

JonathanMagnan avatar Oct 12 '17 12:10 JonathanMagnan

Hi @JonathanMagnan ,

I will try to explain when it happens. class A { --> QueryFilter Applied }

class B : A { }

class dbContext { --> Error DbSet<A> As; DbSet<B> Bs; } class dbContext { --> Works DbSet<A> As; } So if you have a class A that is parent class and child B which inherits from parent A and if TPT is implemented i.e I want a table to be created for both class A and class B in database and I have configured QueryFilter on class A. Now if I add both DbSets As and Bs to the dbContext, then I get mapping error when I try to read from DbSet As i.e parent class in this case. Reading from DbSet Bs works fine.

As a solution, if the DbSet Bs is removed from dbContext, then reading from DbSet As throws no error. For my scenario as of now, removing DbSet Bs was possible since where ever I was required to query on DbSet Bs, I replaced it with dbContext.As.typeOf(B).

I closed my issue when I figured this out. I hope this is understandable and helps someone facing a similar issue.

Regards, Saurabh

saurabh-shelgaonkar avatar Oct 13 '17 13:10 saurabh-shelgaonkar

Hello @saurabh-shelgaonkar ,

Thank you for this additional information.

I have re-opened it since I would like to investigate and fix it. I don't think it will be pretty hard (I may be wrong).

Best Regards,

Jonathan

JonathanMagnan avatar Oct 13 '17 14:10 JonathanMagnan

Hi @JonathanMagnan ,

I was again trying to reconfigure a similar situation in a different project when I realized what had gone wrong earlier. It seems, while configuring TPT inheritance in Entity Framework, the child class DbSets are not supposed to be added to the context. Only parent class DbSet is added to the context. So it seems, this wasn't a issue with EFPlus but with my configuration and Entity Framework itself.

Sorry for the trouble and I feel it is safe to close this issue as it is not a problem with EFPlus.

Thanks!

saurabh-shelgaonkar avatar Feb 26 '18 10:02 saurabh-shelgaonkar