1、安装VS;
2、安装NuGet;
从NuGet官方网站下载安装最新版的NuGet,网址 http://nuget.org/
安装以后重启VS2010后控制台显示如下:
每个程序包的所有者将相应程序包授权给您。Microsoft 不负责也不会授予对第三方程序包的任何许可。有些程序包可能包含受其他许可证控制的依赖项。请访问程序包源(源) URL 以确定所有依赖项。
程序包管理器控制台主机版本 2.1.31002.9028
键入“get-help NuGet”以查看所有可用的 NuGet 命令。
PM> Install-Package EntityFramework
您正在从 Microsoft 下载 EntityFramework,有关此程序包的许可协议在 http://go.microsoft.com/fwlink/?LinkId=253898&clcid=0x409 上提供。请检查此程序包是否有其他依赖项,这些依赖项可能带有各自的许可协议。您若使用程序包及依赖项,即构成您接受其许可协议。如果您不接受这些许可协议,请从您的设备中删除相关组件。
已成功安装“EntityFramework 5.0.0”。
已成功将“EntityFramework 5.0.0”添加到 MvcMusicStore。
Type 'get-help EntityFramework' to see all available Entity Framework commands.
3、安装sqlserver
<connectionStrings>
<add name="applicationservices" connectionString="Server=PFKJ-YFB01\PFKJ;Persist Security Info=true;Initial Catalog=UserInfoForPFKJ;Integrated Security=false;User ID=xxxx;Password=xxxx;" providerName="System.Data.sqlClient" />
<add name="CMsstore" connectionString="Server=localhost;Persist Security Info=true;Initial Catalog=CMsstore;Integrated Security=false;User ID=xx;Password=xxx;" providerName="System.Data.sqlClient" />
</connectionStrings>
5、EF初始化model Global.asax
protected void Application_Start(){
AreaRegistration.RegisterallAreas();
Database.Setinitializer<CMS_PF.Models.CMsstore>(new DropCreateDatabaseIfModelChanges<CMS_PF.Models.CMsstore>());
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
6、建立seed 种子初始化数据
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; namespace CMS_PF.Models { public class InitalData : DropCreateDatabaseIfModelChanges<CMsstore> { protected override void Seed(CMsstore context) { new List<DF_BillTypeMgmt> { new DF_BillTypeMgmt { BeginDate=DateTime.Now,BillCode="0000",BillDay=true,BillMonth=true,BillYear= true, BillName="TEST",BillPrefix="TEST",CreatePerson="TEST",CreateTime=DateTime.Now,OrderIndex=0,Remark="TEST",SerialNumberBegin=1,SerialNumberLength=6} }.ForEach(a => context.DF_BillTypeMgmt.Add(a)); } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。