安装框架:
在NuGet中安装ef框架,命令:Install-package EntityFramework
数据迁移:
在程序包管理器控制台,执行语句。
初始化:
1、Enable-Migrations -EnableAutomaticMigrations
2、Add-Migration InitialCreate
3、Update-Database -Verbose
更新数据库:
1、Add-Migration ChangeTable
2、Update-Database -Verbose
EF数据查询效率对比:
出处:https://www.cnblogs.com/zhaopei/p/5721789.html
1、
var scores = db.Scores.Take(5).ToList();//本质:没有连表 foreach (var item in scores) { var name = item.Student.Name;//每次循环 都会产生一条sql }
2、
var scores = db.Scores.Take(5).Include(c => c.Student).ToList(); foreach (var item in scores) { var name = item.Student.Name; }
3、
var scores = db.Scores .Take(5) .Include(c => c.Student) .Select(c => new { c.ChineseFraction, c.CreateTime, StudentName = c.Student.Name }) .ToList(); foreach (var item in scores) { var name = item.StudentName; }