Entity Framework complex types

Source: Internet
Author: User

To illustrate what a complex attribute is, let's give an example.

 
Public class companyaddress {public int ID {Get; set;} Public String companyName {Get; set;} Public String streetaddress {Get; set;} Public String city {Get; set ;} public String state {Get; set;} Public String zipcode {Get; Set ;}} public class familyaddress {public int ID {Get; Set ;} Public String streetaddress {Get; set;} Public String city {Get; set;} Public String state {Get; set;} Public String zipcode {Get; Set ;}}

There are two classes: company address and home address. They have four identical attributes: streetaddress, city, state, and zipcode. Structure mapped to the database

Here, we can combine these four attributes into a complex attribute address. The modified class is:

Public class companyaddress {public int ID {Get; set;} Public String companyName {Get; set;} Public Address {Get; Set ;}} public class familyaddress {public int ID {Get; set;} Public Address {Get; Set ;}} [complextype] public class address {Public String streetaddress {Get; set ;} public String city {Get; set;} Public String state {Get; set;} Public String zipcode {Get; Set ;}}

The generated database

We can see that the two tables still have the corresponding address attribute information. The address class in the Code is a complex attribute, which is not mapped to the corresponding table in the database, but our code is much simpler.

Therefore, if several attributes are useful in several classes, you can set these attributes into a complex type and add the attribute of this complex type to the corresponding class.

Entity Framework complex types

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.