C# 我应该如何处理生成的DbContext?

C# 我应该如何处理生成的DbContext?,c#,asp.net,asp.net-mvc,entity-framework,linq,C#,Asp.net,Asp.net Mvc,Entity Framework,Linq,我在数据库中使用了Entity的代码生成工具,它为我提供了上下文 //------------------------------------------------------------------------------ // <auto-generated> // This code was generated from a template. // // Manual changes to this file may cause unexpected beh

我在数据库中使用了Entity的代码生成工具,它为我提供了上下文

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated from a template.
//
//     Manual changes to this file may cause unexpected behavior in your application.
//     Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace LRVault.Models
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class LRC_VAULTEntities : DbContext
    {
        public LRC_VAULTEntities()
            : base("name=LRC_VAULTEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<Post> Posts { get; set; }
        public virtual DbSet<Thread> Threads { get; set; }
    }
}

但是,在我创建
RC\u VAULTENtities
的实例之后,没有
Posts
属性。那我该怎么办

使用
Base
类并添加对项目的引用,以便可以在任何需要的地方调用
dbContext

public class Base
    {
        protected internal LRC_VAULTEntities dbContext;

        public Base()
        {
            dbContext = new LRC_VAULTEntities ();
        }
    }

看起来像是
LRC\u VAULTEntities
LRC\u VAULTEntities
之间的键入错误,因为代码显示
Posts
属性存在于DbContext@Nkosi,不,那不是问题issue@DeadlyNicotine嗯,有一个打字错误的地方-因为这不一定是相关的EF在所有。您已显式声明
Posts
为属性,因此您几乎肯定引用了错误的类。@Rob我在它的实例上“转到定义”,这将我带到我粘贴在上面的类如果您只是尝试实例化上下文并运行调试会话,您会得到任何错误吗?在上下文之外是否有可用的属性?
public class Base
    {
        protected internal LRC_VAULTEntities dbContext;

        public Base()
        {
            dbContext = new LRC_VAULTEntities ();
        }
    }