Entity Framework

C

chris.kennedy

I am really struggling to create an entity which maps to 2 "base"
entities. I have a customer and invoice entity which are based in
tables in a one to many relationship. I have tried:

1. Creating a Invoice Entity based on the Invoice and adding a mapping
to both tables: I can't validate the model it says "Two entities with
different keys are mapped to the same row. Ensure these two mapping
fragments do not map two groups of entities with overlapping keys to
the same group of rows." When I add mappings to tables there is no way
to map to the primary key of invoices but when I validate it says
"Problem in Mapping Fragment starting at line 102: Must specify
mapping for all key properties "

Basically I want to create an entity something similar to a view. I am
I misunderstanding how the entity framework works?
 
C

Cowboy \(Gregory A. Beamer\)

Entity Framework is designed to create objects out of data. If you use the
standard drag and drop model, you can drag the two tables and you will then
have a parent object and 0 to n child objects.

If you want to use it like a view, you are better to connect to stored
procedure(s) or a view for your entity, depending on what you are doing with
the data in your application.
 
F

Fresno Bob

I thought the whole point of EF was to create objects like this - so you can
map O-O things like inheritence onto your database.
 
C

Cowboy \(Gregory A. Beamer\)

Fresno Bob said:
I thought the whole point of EF was to create objects like this - so you
can map O-O things like inheritence onto your database.

Ideally, yes. But in the 1.0 release, it hits the 80%, if that. I am a bit
disappointed with it, personally. I would rather use LINQ to SQL, and I have
some reservations with LINQ to SQL as a data layer.

The model currently laid out works well if you are mapping tables to objects
and keeping the basic layout. It can work with some other scenarios, but
falls a bit short when you get any complexity in your model. This is where
mapping the entities to SQL (like sprocs) works well.

I am not trying to sell you on Entity Framework. I think it works well for
the masses, but find it far too easy to step outside of the box. I wish I
could give a better story, but it is not there yet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top