WPF实体无法创建视图的ObjectSet?

Sha*_*boo 5 c# wpf entity-framework

我已经为我的实体模型添加了一个数据库视图.现在我想把一个ObjectSet放入我的ObjectContext所以我可以访问我的应用程序中的视图.

对于常规表,我ObjectSet看起来像这样:

private ObjectSet<StarVendor> _StarVendor;
public ObjectSet<StarVendor> StarVendor
{
    get
    {
        if ((_StarVendor == null))
        {
            _StarVendor = base.CreateObjectSet<StarVendor>("Stratus_X_TestEntities.StarVendors");
        }
         return _StarVendor;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我对我的观点做了同样的事情:

private ObjectSet<CatalogItemSearch> _CatalogItemSearch;
public ObjectSet<CatalogItemSearch> CatalogItemSearch
{
    get
    {
        if ((_CatalogItemSearch == null))
        {
            _CatalogItemSearch = base.CreateObjectSet<CatalogItemSearch>("Stratus_X_TestEntities.CatalogItemSearch");
        }
        return _CatalogItemSearch;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当代码运行时,我得到一个例外:

System.InvalidOperationException"无法找到EntitySet名称'Stratus_X_TestEntities.CatalogItemSearch'"

我知道对于View我不需要提供的添加/更新/删除功能ObjectSet.

是否有我应该使用的替代Set类型?

或者这个错误可能来自与其观点完全无关的事情?

谢谢

bub*_*ubi 1

如果您使用 CodeFirst,您始终可以在映射表(使用 DbSet)时映射视图,然后它应该可以工作。