Entity Framework Complex Types
阿新 • • 發佈:2018-02-26
string public work 分享 base framework name entity con
1.模型類
public class Order { public int OrderId { get; set; } public string OrderNumber { get; set; } public DateTime OrderData { get; set; } public string DisposeDate { get; set; } public Address ShipAddress { get; set; } public Address BillAddress { getView Code; set; } } public class Address { public string FirstName { get; set; } public string LastName { get; set; } public string Addr { get; set; } public string Street { get; set; } public string City { get; set; } public string ZipCode { get; set; } public string Email { get; set; } public string Phone { get; set; } public string State { get; set; } public string Country { get; set; } }
2.寫入數據庫
using (var db = new BaseDbContext()) { var address = new Address { FirstNameView Code="浙江省", LastName="溫嶺市" }; var address2 = new Address { FirstName = "浙江省", LastName = "椒江" }; Order order = new Order { ShipAddress = address, BillAddress = address2, OrderData=DateTime.Now, OrderNumber="001" }; db.Orders.Add(order); db.SaveChanges(); }
Entity Framework Complex Types