我在我的数据库中使用了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; }
}
}
我希望能够像
那样立即使用它var context = new LRC_VAULTENtities();
context.Posts.InsertOnSubmit(new Post() { ... });
context.Posts.SubmitChanges();
但是在创建Posts
的实例后,没有RC_VAULTENtities
属性。那我该怎么办?
答案 0 :(得分:0)
使用Base
课程并添加对项目的引用,以便您可以随时随地拨打dbContext
。
public class Base
{
protected internal LRC_VAULTEntities dbContext;
public Base()
{
dbContext = new LRC_VAULTEntities ();
}
}