标签:
public class Orders { [Key] //主键 public int Id { get; set; } [StringLength(10)] //长度 public string OrdersCode { get; set; } public int CustomerID { get; set; } public System.DateTime CreateDate { get; set; } public virtual List<OrdersDetail> OrdersDetailList { get; set; } } public class OrdersDetail { [Key] //主键 public int Id { get; set; } public int ProductID { get; set; } [StringLength(100)]//长度 public string ProductName { get; set; } public string UnitPrice { get; set; } public int OrderId { get; set; } public virtual Orders Orders { get; set; } }
下一步,通过NuGet安装EntityFramework。
public class OrdersContext : DbContext { public DbSet<Orders> Orders { get; set; } public DbSet<OrdersDetail> OrdersDetail { get; set; } }
客户端调用
class Program { static void Main(string[] args) { var d = DateTime.Now.Date.ToString("yyyyMM"); var ord = new Orders { OrdersCode = "100001", CustomerID = 1, CreateDate = DateTime.Now }; using (var context = new OrdersContext()) { context.Orders.Add(ord); context.SaveChanges(); } Console.WriteLine("OK"); Console.ReadLine(); } }
标签:
原文地址:http://www.cnblogs.com/itmu89/p/5384791.html