有人使用实体框架*好吧*吗?
-
09-06-2019 - |
题
是否有人实际发布了一个实体框架项目,该项目将 O/R 映射到与数据存储中的表完全不同的概念类?
我的意思是折叠连接(M:M)表到其他实体中以形成 概念性的 存在于业务领域但组织为的类 多张桌子 在数据存储中。我在 MSDN 上看到的所有示例都很少使用继承、将联结表折叠到其他实体中,或者将查找表折叠到实体中。
我很想听到或看到下面的示例,它们支持您通常期望在业务对象上执行的所有 CRUD 操作:
车辆表和颜色表。一种颜色可以出现在许多车辆中 (1:M)。它们形成了概念类UsedCar,它具有属性Color。
Doctor、DoctorPatients 和患者表(形成多对多)。医生有很多病人,病人可以有很多医生(M:M)。绘制两个概念类“医生”(具有“患者”集合)和“患者”(具有“医生”集合)。
有人在实体框架中使用 CSDL 和 SSDL 见过/做过这个吗?如果 CSDL 不能真正映射到任何东西,那么它就没有用!
解决方案
我尝试在现有项目(约 60 个表,3 个具有继承)上使用实体框架,只是为了看看它到底是什么。我的经验归结为:
设计者的表面很混乱。这种映射并不直观,有人一定认为同时打开多个工具窗口是可以接受的。手动创建对象并映射正确的字段需要很长时间 - 然后从代码中与它交谈仍然很奇怪。虽然处理数据库通信的东西是必不可少的, 我觉得将控制权交给 EF 比手动进行要困难得多.
有时,直到您重新启动 Visual Studio 后,设计器才会加载。我确信这只是一个错误,但重新启动 VS 很烦人。
您的所有工作最终都在一个文件中,我不想合并多个开发人员版本。
生成的 SQL(通过 Profiler 观察)不太好。我并没有真正深入研究原因,但你会被迫在第一次尝试时写出更糟糕的东西。
其他提示
这就是我要说的...
你的意思是这样吗?
<edmx:ConceptualModels>
<Schema xmlns="http://schemas.microsoft.com/ado/2006/04/edm" Namespace="Model1" Alias="Self">
<EntityContainer Name="Model1Container" >
<EntitySet Name="ColorSet" EntityType="Model1.Color" />
<EntitySet Name="DoctorSet" EntityType="Model1.Doctor" />
<EntitySet Name="PatientSet" EntityType="Model1.Patient" />
<EntitySet Name="UsedCarSet" EntityType="Model1.UsedCar" />
<AssociationSet Name="Vehicle_Color" Association="Model1.Vehicle_Color">
<End Role="Colors" EntitySet="ColorSet" />
<End Role="Vehicles" EntitySet="UsedCarSet" /></AssociationSet>
<AssociationSet Name="DoctorPatient" Association="Model1.DoctorPatient">
<End Role="Doctor" EntitySet="DoctorSet" />
<End Role="Patient" EntitySet="PatientSet" /></AssociationSet>
</EntityContainer>
<EntityType Name="Color">
<Key>
<PropertyRef Name="ColorID" /></Key>
<Property Name="ColorID" Type="Int32" Nullable="false" />
<NavigationProperty Name="Vehicles" Relationship="Model1.Vehicle_Color" FromRole="Colors" ToRole="Vehicles" /></EntityType>
<EntityType Name="Doctor">
<Key>
<PropertyRef Name="DoctorID" /></Key>
<Property Name="DoctorID" Type="Int32" Nullable="false" />
<NavigationProperty Name="Patients" Relationship="Model1.DoctorPatient" FromRole="Doctor" ToRole="Patient" /></EntityType>
<EntityType Name="Patient">
<Key>
<PropertyRef Name="PatientID" /></Key>
<Property Name="PatientID" Type="Int32" Nullable="false" />
<NavigationProperty Name="Doctors" Relationship="Model1.DoctorPatient" FromRole="Patient" ToRole="Doctor" />
</EntityType>
<EntityType Name="UsedCar">
<Key>
<PropertyRef Name="VehicleID" /></Key>
<Property Name="VehicleID" Type="Int32" Nullable="false" />
<NavigationProperty Name="Color" Relationship="Model1.Vehicle_Color" FromRole="Vehicles" ToRole="Colors" /></EntityType>
<Association Name="Vehicle_Color">
<End Type="Model1.Color" Role="Colors" Multiplicity="1" />
<End Type="Model1.UsedCar" Role="Vehicles" Multiplicity="*" /></Association>
<Association Name="DoctorPatient">
<End Type="Model1.Doctor" Role="Doctor" Multiplicity="*" />
<End Type="Model1.Patient" Role="Patient" Multiplicity="*" /></Association>
</Schema>
</edmx:ConceptualModels>