有人在使用实体框架吗?

时间:2020-03-05 18:51:51  来源:igfitidea点击:

是否有人实际交付过将O / R映射到与数据存储区中的表完全不同的概念性类的Entity Framework项目?

我的意思是将折叠结(M:M)表转换为其他实体,以形成业务领域中存在的概念类,但在数据存储区中被组织为多个表。我在MSDN上看到的所有示例都很少使用继承,将联结表折叠到其他实体中或者将查找表折叠到实体中。

我很乐意听到或者看到以下示例,这些示例支持我们通常希望对业务对象执行的所有CRUD操作。:

  • 车辆表和颜色表。颜色可以出现在许多车辆(1:M)中。它们构成了概念类UsedCar,其属性为Color。
  • Doctor,DoctorPatients和Patient表(多对多)。医生有很多病人,病人可以有很多医生(M:M)。绘制出两个概念性类Doctor(具有"患者"集合)和"患者"(具有"医生"集合)。

有人在实体框架中使用CSDL和SSDL看到/完成了此操作吗?如果CSDL不能真正映射到任何东西,那就不好了!

解决方案

回答

我试图在现有项目(约60个表,有3个继承)上使用实体框架,只是为了了解它的全部含义。我的经验可以归结为:

设计器表面粗糙。映射不是直观的,必须有人认为同时打开多个工具窗口是可以接受的。手动创建对象并映射正确的字段花了很长时间,然后从代码中谈论它仍然很奇怪。尽管必须要处理数据库通信,但我觉得将控制权交给EF远比手动完成要困难得多。

有时,设计器只是直到重新启动Visual Studio才会加载。我确定这只是一个错误,但是重新启动VS很烦人。

所有工作最终都保存在一个文件中,Id讨厌合并多个开发人员版本。

生成的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>

回答

实体框架不信任投票

那就是我要说的