In EF4, multiple tables are mapped to an object.

Source: Internet
Author: User

There are two tables with the same primary key. here we need to map these two tables into an object.

 

 Select the two tables into EDM:

 

 Next we will map the two tables into an object:

1. Copy the productimage in the Entity productimage to the entity product.

2. Delete the productimage object. A prompt is displayed, indicating whether to delete the table from the storage model.

 

3. Click the object product to view the Mapping Details window.

4. In the detaing Details window, click "add a table or view" to select the table productimage.

 

 In this way, the modified model is like the following. The two tables are combined into an object model:

 

 

 Adding a new column in our existing system table seems normal, but sometimes it is unwilling to add a new column to change the existingCodeIn this way, we can add the new columns to be added to a separate table.

This process of combining two tables into one entity is called vertical splitting)

 The disadvantage of Vertical Split is that each table has an innerjoin operation. We can see through the following code:

 Code

Using (Efdemoentities Context =   New Efdemoentities ())
{
Objectquery < Product > Productquery = Context. product;
Console. writeline (productquery. totracestring ());
}

 

 

Output result

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.