-
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
Map to customized (dynamically generated but with same structure) tables entity framework core #15753
Comments
@hnviradiya Can you explain a bit more how you would use this kind mapping? For example, what would be the code you would write for a query against "table_3"? Also, would all tables have the same columns? If not, how would this be handled? (I'm asking these questions to try to distill down to what EF would need to support for this to work.) |
All tables have same db structure (basically this is a partition of own implementation to handle large datasets). So if I want to query against "table_3", I can write as "dbcontext.DbSet<Table>("table"+ passedId)" isn't this possible? |
@hnviradiya So then what is the CLR type |
Table is a model (not dbset, but model). because all tables have same structure we can use it in generic way? |
@hnviradiya Okay, so you do have a class that you want to map, you just want to dynamically change which table it maps to. Is this correct? |
yes :) |
Generating query for such tables is not a problem. But it also needs ChangeTracker extension point. @hnviradiya, i suggest to tryout this extension 👽 var items = context.DbSet<Table>().ToLinqToDBTable().TableName("table_3")
.Where(...)
.ToList(); For sure ChangeTracker will be not availaible but CRUD operation can be performed in other way: var affected = context.DbSet<Table>().ToLinqToDBTable().TableName("table_3")
.Where(...)
.Set(v => v.Field, someValue)
.Update(); |
Great, that will work for me. Thanks :) |
This is essentially a duplicate of #15671 |
What's the best course of action now ? The sdanyLIV scheme above is now not working ? |
Hi |
I also have this issue. |
Can't there be a mapping of multiple tables (dynamically N tables) to same class.
I have multiple tables generated at runtime. I want to query them. What is a solution to this?
Cant create classes. As tables are generated at runtime.
E.g. table_1, table_2. table_3, ...table_N should map to "table" class. To which I should be able to provide parameter that which table to query on.
Currently onmodelcreating we are using fixed string method named "toTable". Where we can provide fixed string of table name we want to map to. It would be great if we can provide this dynamically.
there are multiple requirements like this on stackoverflow for which people are not getting answered for as per requirement of OP.
https://stackoverflow.com/questions/56135928/map-to-customized-dynamically-generated-but-with-same-structure-tables-entity/56202714#56202714
https://stackoverflow.com/questions/38372618/multiple-tables-with-same-structure-entity-framework
https://stackoverflow.com/questions/31035238/dynamic-table-name-with-entity-framework
The text was updated successfully, but these errors were encountered: