码迷,mamicode.com
首页 > 其他好文 > 详细

Entity Framework Complex Types

时间:2018-02-26 11:29:38      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:count   seda   分享   save   data   com   ber   pad   pre   

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 { get; 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; }
    }
View Code

2.写入数据库

技术分享图片
            using (var db = new BaseDbContext())
            {
                var address = new Address { 
                    FirstName="浙江省",
                    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();
            }
View Code

 

Entity Framework Complex Types

标签:count   seda   分享   save   data   com   ber   pad   pre   

原文地址:https://www.cnblogs.com/liandy0906/p/8471773.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!