4 Star 5 Fork 2

xant/EF6CodeFirstSimpleDemo

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
DataModelInitializer.cs 1.30 KB
Copy Edit Raw Blame History
xant authored 2015-02-10 12:35 +08:00 . 项目初建
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EF6CodeFirstMySQL.Model
{
public class DataModelInitializer : DropCreateDatabaseIfModelChanges<DataModelContext> // CreateDatabaseIfNotExists<DataModelContext>
{
protected override void Seed(DataModelContext context)
{
var contracts = new List<Contract>
{
new Contract{ BillNo = "PO20150201-001", BillDate=new DateTime(2015, 2, 1), TotalPrice=9876543.21M, Supplier = "Microsoft"},
new Contract{ BillNo = "PO20141230-088", BillDate=new DateTime(2014, 12, 30), TotalPrice=1234567.89M, Supplier = "Oracle"},
};
context.Contracts.AddRange(contracts);
context.SaveChanges();//可以分次提交,也可以最后一次性提交给数据库
var deliveries = new List<DeliveryNote>
{
new DeliveryNote{ BillNo = string.Format("DN{0:yyyyMMdd}-006", DateTime.Today), TotalPrice=445566M, Contract=contracts.First(), Checker="张三"},
};
context.DeliveryNotes.AddRange(deliveries);
context.SaveChanges();//可以分次提交,也可以最后一次性提交给数据库
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/xant77/EF6CodeFirstSimpleDemo.git
git@gitee.com:xant77/EF6CodeFirstSimpleDemo.git
xant77
EF6CodeFirstSimpleDemo
EF6CodeFirstSimpleDemo
master

Search