长话短说,如果你查看my project,你可以看到我有一个automatically generated model,但在导入模式的命名空间并尝试使用它之后
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LRVault.Models;
using System.Data.Linq;
namespace LRVault.Repositories
{
public class ThreadRepository : VaultCRUD
{
public void AddOrUpdateThreads(IEnumerable<Thread> threads)
{
VaultContext.???
}
}
}
我无法获得表格,即VaultContext.Posts
无法识别。我错过了什么?
编辑:父类是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Linq;
using LRVault.Models;
using System.Data.Entity;
namespace LRVault.Repositories
{
/// <summary>
/// Serves as base class for the CRUD operations
/// </summary>
public abstract class VaultCRUD : IDisposable
{
public DbContext VaultContext { get; private set; }
public VaultCRUD()
{
VaultContext = new LRC_VAULTEntities();
}
public void Dispose()
{
VaultContext.Dispose();
}
}
}
答案 0 :(得分:2)
您需要将VaultContext属性强制转换为LRC_VAULTEntities
,才能访问表格:
(VaultContext as LRC_VAULTEntities).
DbContext
是LRC_VAULTEntities
的基类,但“表格”位于LRC_VAULTEntities
。
答案 1 :(得分:0)
您需要创建一个实例
using(var context = new VaultContext())
{
}
答案 2 :(得分:0)
VaultContext
实例声明类型为DbContext
,与您的表格无关,您必须将其类型更改为LRC_VAULTEntities
,执行此操作后您将获得表格你想要的继承类