我创建了一个类库,用于实现项目的逻辑,但是当我尝试运行我的代码时,会显示以下错误:
无法加载文件或程序集EntityFramework ...
我认为此错误毫无意义,因为EF6已安装在我的Visual Studio 2013上。
在app.config
内我定义了一个连接字符串:
<connectionStrings>
<add name="con0"
connectionString="Persist Security Info=False;Integrated Security=true;Initial Catalog=jasmin;server=(local)"
providerName="System.Data.sqlclient" />
</connectionStrings>
这是我的上下文类:
public class SchoolClassContext : DbContext
{
public SchoolClassContext() : base("name=con0") { }
public DbSet<SchoolClass> SchoolClassCtx;
public DbSet<Teacher> TeacherCtx;
public DbSet<List<Student>> StudentsCtx;
}
这是我的方法:
public virtual TransActionInfo AddClass()
{
transActionInfo = new TransActionInfo();
classContext = new SchoolClassContext();
var schoolclass = new SchoolClass() {
ClassID = base.ClassID,
Title = base.Title,
Location = base.Location,
Schedule = base.Schedule,
State = base.State,
TTeacher = base.TTeacher,
Students = base.Students
};
try
{
classContext.SchoolClassCtx.Add(schoolclass);
classContext.SaveChanges();
transActionInfo.Status = TransactionStatus.Status.Successful;
transActionInfo.ObjectName = base.GetType().Name;
transActionInfo.ObjectLastState = schoolclass;
transActionInfo.TransactionTime = DateTime.Now;
return transActionInfo;
}
catch(Exception e)
{
transActionInfo.Status = TransactionStatus.Status.Abort;
transActionInfo.Msg = e.ToString();
transActionInfo.TransactionTime = DateTime.Now;
return transActionInfo;
}
}
有什么建议吗?
答案 0 :(得分:1)
使用NuGet-Packagemanager安装EntityFramework后,您应该确保在引用列表中有EntityFramework:
构建解决方案后,您的调试文件夹中应该有一个EntityFramework.dll与您自己的可执行文件并排:
希望有所帮助
答案 1 :(得分:0)
尝试使用nuget包管理器控制台在项目中安装EF。