首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法查看实体框架中创建的数据库

无法查看实体框架中创建的数据库
EN

Stack Overflow用户
提问于 2015-03-10 11:26:26
回答 1查看 1.1K关注 0票数 2

这可能是实体框架工作开发人员的基本问题,希望从数据库开发人员转变为具有实体框架模型的基本示例的Dot net developer.Started,但在编译过程中遇到以下异常。下面是我的主要方法。

代码语言:javascript
运行
复制
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();
            }
        }
    }
}

下面是创建数据库表的类。

代码语言:javascript
运行
复制
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;

代码语言:javascript
运行
复制
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]在一起

此外,还要求您建议启动实体框架的最佳位置。

EN

回答 1

Stack Overflow用户

发布于 2015-03-31 15:11:07

当我执行此转换时,我的数据库是在Server = (localdb)\mssqllocaldb中创建的,请尝试连接到此数据库,然后在数据库下检查

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28962504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档