这可能是实体框架工作开发人员的基本问题,希望从数据库开发人员转变为具有实体框架模型的基本示例的Dot net developer.Started,但在编译过程中遇到以下异常。下面是我的主要方法。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace EFMAin
{
class Program
{
static void Main(string[] args)
{
using (var ctx = new SchoolContext())
{
Student stud = new Student() { StudentName = "New Student" };
ctx.Students.Add(stud);
ctx.SaveChanges();
}
}
}
}下面是创建数据库表的类。
using ExampleCF.Models;
using ExampleCFA.Models;
using System.Collections.Generic;
namespace ExampleCF.Models
{
public class Teacher
{
public int TeacherId { get; set; }
public string TeacherName { get; set; }
public string Address { get; set; }
public ICollection<Student> Students { get; set; }
}
}
namespace ExampleCFA.Models
{
public class Student
{
public int StudentId { get; set; }
public string Name { get; set; }
public string Class { get; set; }
public int TeacherId { get; set; }
public Teacher Teacher { get; set; }
}
}下面是上下文类。使用System.Data.Entity;
namespace EF_Code_First_Tutorials
{
public class SchoolContext : DbContext
{
public SchoolContext()
: base()
{
}
public DbSet<Student> Students { get; set; }
public DbSet<Standard> Standards { get; set; }
}
}在编译此应用程序时遇到以下异常。
错误3 'System.Runtime.Remoting.Contexts.Context‘不包含'SaveChanges’的定义,也找不到接受'System.Runtime.Remoting.Contexts.Context‘类型的第一个参数的扩展方法'SaveChanges’(您缺少使用指令还是程序集引用?)D:\EF\EFLab1Practice\EFCodeFirst\EFMAin\Program.cs 20 21 EFMAin 错误2 'System.Runtime.Remoting.Contexts.Context‘不包含’学生‘的定义,也找不到扩展方法’学生‘接受'System.Runtime.Remoting.Contexts.Context’类型的第一个参数(您是缺少使用指令还是程序集引用?)D:\EF\EFLab1Practice\EFCodeFirst\EFMAin\Program.cs 19 21 EFMAin错误1‘System.Runtime.Remoting.Contexts.Context:使用语句中使用的类型必须隐式转换为'System.IDisposable’D:\EF\EFLab1Practice\EFCodeFirst\EFMAin\Program.cs 15 13 EFMAin
任何人都请建议什么是这方面的起点。
我跟[http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx][1]在一起
此外,还要求您建议启动实体框架的最佳位置。
发布于 2015-03-31 15:11:07
当我执行此转换时,我的数据库是在Server = (localdb)\mssqllocaldb中创建的,请尝试连接到此数据库,然后在数据库下检查
https://stackoverflow.com/questions/28962504
复制相似问题