4

After hunting around the net, and thinking I'd come up with the solution, I seem to have hit another brick wall.

I have a table in my database: Photos; containing columns for PhotoID, Caption, Ordering, and four sets of binary data: Original, Large, Medium and Small (yes, it was based on the old ASP.NET starter kit with various fixes, etc).

I'm in the process of moving from L2S to Entity Framework for some of the advantages I appear to get with that - so I no longer need to go through a PhotosTags property to get the list of Tags attached to a photo for example, but I'm looking for a way to delay loading the binary data - most of the time, I only need caption, tag, and ID, and I then hand these off to another area to get the binary data when a user actually views the image.

I've taken a look at the following posts:

  1. How to split a data table?
  2. “Table Splitting”: Mapping multiple entity types to the same table.
  3. Chapter 7 of: Entity Framework Learning Guide (7.1 Delay loading of expensive fields)

And I ended up with an Entity Mapping looking like this:

Entity Diagram

And, as per the links above, I modified the edmx file to include the following Referential Constraint:

<ReferentialConstraint>
  <Principal Role="Photos">
    <PropertyRef Name="PhotoID" />
  </Principal>
  <Dependent Role="PhotoDetails">
    <PropertyRef Name="PhotoID" />
  </Dependent>
</ReferentialConstraint>

The model validates, but doesn't build - because of an issue with the Tags mapping I think:

Error 3019: Problem in Mapping Fragments starting at lines 871, 892: Incorrect mapping of composite key columns. Foreign key constraint 'FK_siteContent_TagsPhotos_siteContent_Photos' from table siteContent_TagsPhotos (PhotoID) to table siteContent_Photos (PhotoID): Columns (PhotoID) in table siteContent_TagsPhotos are mapped to properties (PhotoID) in siteContent_TagsPhotos and columns (PhotoID) in table siteContent_Photos are mapped to properties (PhotoID) in PhotosPhotoDetails. The order of the columns through the mappings is not preserved.

The relationship from Photos to Tags is through a link table, columns PhotoID, TagID.

Has anyone managed to get either those recommendations, or something similar, to work with the Entity Framework in .NET 3.5 SP1 with a data structure like this? Or can you point out the limitations of my GoogleFU?

I know that this will all be much easier in .NET 4, but that's not here, and it will probably be a while after it's released that my host starts offering to install it somewhere.

Thanks.

1 Answer 1

2

I've hit the same issue and while I haven't found a solution for 3.5SP1 I did confirm that this error goes away with EF 4.0.

Actually, a potential workaround for you would be to use a different field for the primary key in your PhotoDetails entity.

Sign up to request clarification or add additional context in comments.

3 Comments

By "different field for the primary key", do you mean just give it a different name, but use the same underlying database column, or add a new column to the database, and use that?
Sadly, I've now tried both options: renaming the scalar property on the entity, which results in the same error message (The order of the columns through the mappings is not preserved), Adding a new column to the database, exposing that in both entities, and using it as the key caused errors along the lines of "You haven't used the Entity Key PhotoID in PhotoDetails". I fear I'm going to have to rework the live database - yay for LinqPad, down with cursors ;)
I meant add a new column to the database and use that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.