Skip to content

Instantly share code, notes, and snippets.

@bradymholt
Last active August 29, 2015 14:03
Show Gist options
  • Save bradymholt/22f9cfa419feb984bba2 to your computer and use it in GitHub Desktop.
Save bradymholt/22f9cfa419feb984bba2 to your computer and use it in GitHub Desktop.
Entity Framework with Complex Types
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