Modelling split entities

A split entity is a single logical entity that’s stored in multiple database tables. That doesn’t really make sense in an OOP environment: All of the properties of an entity should be properties of that entity.

Here’s the model the wizard creates from the split entity schema. You really want the properties of the SplitCustomerBusinessAddress entity included in the SplitCustomer entity.

Image

If you think about what you’d like to do, you just want to paste the properties from one entity to the other and delete the original entity, right? Well, that’s exactly what you can do in the designer—select the properties in one entity, copy them (from the Edit menu, the context menu, or using Ctrl+C) and paste them into the other entity (from one of the menus or using Ctrl+V).

Next you’ll delete the unused SplitCustomerBusinessAddress entity, so select it and press Delete, but when the designer asks, don’t delete the table from the store model. We’ll still need the properties.

There is one extra step, though: You need to tell Entity Framework how to map the properties now that you’ve moved them...read on.

After you copy the properties to the primary entity, the designer knows that they’re there, but it doesn’t know how to map them, so they’re not listed in the Mapping Details Window.

Image

To add the mappings, just click on the <Add a Table or View> cell and choose the original table from the list. (If it isn’t there, you deleted it from the store model. You can readd it using the Update Model wizard.) The designer is smart enough to map all the individual properties for you, and the Entity Framework is smart enough to handle all the merging for you when you reference the properties in code.

Image

Image On Your Own

Using the description on this page, add a new model to the project (you can call it whatever you like, but make sure you use a distinct connection string on the Connection page of the wizard) and merge the SplitCustomerBusinessAddress into the SplitCustomer entity.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset