views:

1146

answers:

3

Has anyone actually shipped an Entity Framework project that does O/R mapping into conceptual classes that are quite different from the tables in the datastore?

I mean collapse junction (M:M) tables into other entities to form Conceptual classes that exist in the business domain but are organized as multiple tables in the datastore. All the examples that I see on the MSDN have little use of inheritance, collapsing junction tables into other entities, or collapsing lookup tables into entities.

I'd love to hear of or see examples of the below which support all the CRUD operations you would typically expect to do on a business object.:

  1. Vehicle table and a Color table. A Color can appear in many Vehicles (1:M). They form the conceptual class UsedCar which has the property Color.

  2. Doctor, DoctorPatients, and Patients tables (form a many to many). Doctors have many Patients, Patients can have many Doctors (M:M). Map out the two conceptual classes Doctor (which has a Patients collection) and Patients (which has a Doctors collection).

Anyone seen/done this with CSDL AND SSDL in the Entity Framework? The CSDL is no good if it doesn't actaully map to anything!

+5  A: 

I attempted to use the Entity Framework on an existing project (~60 tables, 3 with inheritance) just to see what it was all about. My experience boiled down to:

The designer surface is kludgy. The mapping isn’t intuitive and someone must have thought that having several tool windows open at the same time is acceptable. It took a long time to manually create an object and map the right fields – then it was still odd talking to it from the code. While having something handling the database communication is essential, I feel that handing the control over to EF was far more of a fight than doing it manually.

Sometimes the designer just doesn’t load until you restart Visual Studio. I’m sure it’s just a bug but restarting VS is annoying.

All your work ends up in a single file, I’d hate to merge multiple developer editions.

The resultant SQL (watched via the Profiler) wasn’t very good. I didn’t really delve into looking why, but you’d be pressed to write something worse on a first attempt.

Ant
Was this recent or during the beta? I had a pretty sour beta experience that didn't really get me excited about the EF.
Tyler
As soon as I could install the release of SP1 on my work machine and throw an hour at it.
Ant
+2  A: 

You mean like this?

<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>
Mark Cidade
This looks good. It's always been mapping that CSDL onto the SSDL that I've wondered about. Where does the SSDL begin? I guess I'm wondering if this is simply more than us describing the entities with CSDL on a blank designer surface. It's always been the mapping that's been a question to me.
Tyler
+2  A: 

Entity Framework - Vote of no confidence

That's all I have to say...

Vyrotek
Why the downvote?
F.D.Castel