Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们的数据库中有 2 个完全相同的表。一个是另一个的档案。
如何在不使用 Entity Framework 和 Linq 更改实体类型的情况下从存档表中检索数据?
你总是可以做一个.Select(x=>new SomeTypeOfObject{Prop1 = x.Prop1, Prop2 = x.Prop2})
.Select(x=>new SomeTypeOfObject{Prop1 = x.Prop1, Prop2 = x.Prop2})
当您将表映射到 EF 实体时,您可以自动为实体创建类。为什么要避免为不同的表创建单独的类?如果您想要两者的通用合同,以便您可以将它们传递给在两者上执行相同操作的其他函数,我会向生成的实体添加一个接口。这样您就可以使用自动生成的实体,但仍然可以将它们视为“一个”