September 2008 - Posts

ADO.NET Data Services with inheritance and navigation properties

Last week, I speak for the WSC about ADO.NET Data Services (aka Astoria) and I said that it's really great, particularly with EF.

I always think that but I see a non covered scenario which is a big big shame in my opinion:

When you have inheritance between your entity types, you can't have navigation properties in your derived ones. All your navigation properties must be on the base entity type (which is a nonsense).

TPT with designer can generate errors 3034 or 3021

I found two cases of errors generated by the EDM designer when you want to do TPT.

Error 3034:

Imagine the following scenario:

  • A table Contacts
    • ContactID (PK)
  • A table Employees
    • ContactID (PK)
    • OfficeID (Nullable, FK to Offices.OfficeID)
  • A table Offices
    • OfficeIF (PK)

To do TPT between Contacts and Employees with designer, I do the following:

  • I delete the relationship between Employees and Contacts.
  • I also delete Employees.EmployeeID property.
  • Then I add inheritance between Employees and Contacts.
  • Then, always with designer, I remap the Employees entity type and the relationship between Employees and Offices

Here I have an error because the designer "forgets" the condition IsNull=false in the relationship mapping.

Error 3021

Imagine the following scenario:

  • A table Contacts
    • ContactID (PK)
  • A table Employees
    • ContactID (PK)
  • A table Hodidays 
    • EmployeeID (PK, KF to Employees.ContactID)
    • From (PK)

I want to do TPT as previously.

In this case, I have an error 3021 because the designer "forgets" the CSDL association ReferentialConstraint which is inevitable if the FK is in the PK.

 

So ok, there are some bugs in the designer but don't forget that designer is just here for help. So these bugs don't prevented you to use EF. Wink