Use same type against two identical tables in EF Code First

前端 未结 2 1295
名媛妹妹
名媛妹妹 2021-01-24 18:42

I have two tables, Users and TempUsers and I need to do operations on both of them. I already have my users type defined and I want to add it to the DbContext for both tables. P

相关标签:
2条回答
  • 2021-01-24 18:56

    That is not possible. EF cannot map same class twice within same context. Your single User class can be only mapped to Users table or TempUsers table in single context type. You need either two user classes or two different context types (with different mapping configuration) - one providing access to Users table and second providing access to TempUsers table.

    0 讨论(0)
  • 2021-01-24 18:57

    This reminds me of my own question: Querying data using Entity Framework from dynamically created table

    Actually, you can use EF and ExecuteStoreQuery to retreive objects, but you cannot use the LINQ features of EF.

    0 讨论(0)
提交回复
热议问题