Entity framework 如何将实体框架代码优先方法应用于项目
我使用Visual Studio 2013,需要在项目中使用实体框架代码优先的方法。我使用NuGet Manager将EF v6.1安装到我的项目中。但我不能从数据库中创建空的代码优先模型,甚至不能创建代码优先模型,尽管还有两种选择(DB优先和模型优先)Entity framework 如何将实体框架代码优先方法应用于项目,entity-framework,ef-code-first,nuget,Entity Framework,Ef Code First,Nuget,我使用Visual Studio 2013,需要在项目中使用实体框架代码优先的方法。我使用NuGet Manager将EF v6.1安装到我的项目中。但我不能从数据库中创建空的代码优先模型,甚至不能创建代码优先模型,尽管还有两种选择(DB优先和模型优先) 如何将实体框架代码优先功能添加到我的项目中?这是一个关于如何首先使用实体框架代码的初学者教程: 在Nuget中安装EntityFramework 在Web.Config中添加connectionString,并以ConnectDB的名义添加Y
如何将实体框架代码优先功能添加到我的项目中?这是一个关于如何首先使用实体框架代码的初学者教程:
public class Tbl_Student
{
[Key]
public int Id { get; set; }
[Required(AllowEmptyStrings =false)]
[StringLength(maximumLength:40)]
public string Name { get; set; }
[Required(AllowEmptyStrings = false)]
[StringLength(maximumLength: 40)]
public string Family { get; set; }
}
使用System.Data.Entity代码>
public class DataContext:DbContext
{
public DataContext() : base("ConnectDB")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
public virtual DbSet<Tbl_Student> Tbl_Students { get; set; }
}
公共类DataContext:DbContext
{
public DataContext():base(“ConnectDB”)
{
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
}
公共虚拟数据库集Tbl_学生{get;set;}
}
“模型优先”和“代码优先”不一样吗?我知道“模型优先”是一种我们应该创建模型的方法,它也可以是图形模型,但在“代码优先”方法中,我们只是用C#或VB编程类。@tmckown:当然不是。好的,我只是将工程从DB反向到了“代码优先”。。。