Last active
August 29, 2015 14:03
-
-
Save bradymholt/22f9cfa419feb984bba2 to your computer and use it in GitHub Desktop.
Entity Framework with Complex Types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
public string FirstName {get;set;} | |
public string LastName {get;set;} | |
public Address = new Address(); // << It's important to instantiate Address. | |
} | |
[ComplexType] // << This attribute is important. | |
public class Address { | |
public string Address1 {get;set;} | |
public string Address2 {get;set;} | |
public string City {get;set;} | |
} | |
/*Example usage: | |
Person p = new Person(); | |
p.Address.Address1 = "1848 Willow Drive"; | |
p.Address.Address2 = "Unit 105"; | |
p.Address.Address1 = "Houston"; | |
*/ | |
/* Table structure | |
dbo.Person | |
FirstName varchar(50), | |
LastName varchar(50), | |
Address1 varchar(50), | |
Address2 varchar(50), | |
City varchar(50) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment