首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MVC 4 Entity Framework 4 POCO:指定的架构无效

MVC 4 Entity Framework 4 POCO:指定的架构无效
EN

Stack Overflow用户
提问于 2012-03-17 00:06:27
回答 1查看 1.6K关注 0票数 1

以下是我似乎无法修复的错误:

代码语言:javascript
复制
Schema specified is not valid. Errors: 
The relationship 'Repository.ForumCategory' was not loaded because the type 'RepositoryModel.ForumCategories' is not available.

这是我的ForumCategory类:

代码语言:javascript
复制
public class ForumCategory
{
    //
    // Scalar Properties
    public int Id { get; set; }

    public string Name { get; set; }

    public int Order { get; set; }

    public virtual ICollection<Forum> Forums { get; set; }
}

这是我的论坛类:

代码语言:javascript
复制
public class Forum
{
    //
    // Scalar Properties
    public int Id { get; set; }

    public int CategoryId { get; set; }

    public string Icon { get; set; }

    public string Name { get; set; }

    public string Description { get; set; }

    public int ThreadCount { get; set; }

    public int PostCount { get; set; }

    public virtual Nullable<DateTime> LastPostDate { get; set; }

    public int Order { get; set; }

    //
    // Navigation Properties
    public virtual ForumCategory Category { get; set; }
}

这是我的RepositoryContext:

代码语言:javascript
复制
public class RepositoryContext : ObjectContext
{
    private IObjectSet<ForumCategory> _forumCategories;
    private IObjectSet<Forum> _forums;

    public SHRepositoryContext()
        : base("name=Repository", "Repository")
    {
        ContextOptions.LazyLoadingEnabled = true;
        _forumCategories = CreateObjectSet<ForumCategory>();
        _forums = CreateObjectSet<Forum>();
    }
    public IObjectSet<ForumCategory> ForumCategories
    {
        get { return _forumCategories; }
    }

    public IObjectSet<Forum> Forums
    {
        get { return _forums; }
    }
}

这是我的实体模型:

真的需要帮助,我读了一些人的回答,但似乎没有一个是相关的=\

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-24 20:41:47

问题是:我在模型中有一个关联覆盖了我的ForumCategory名称。解决方案是:我将关联重命名为Forum_Category,并将实体重命名为ForumCategory。这解决了我的问题!

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

https://stackoverflow.com/questions/9740663

复制
相关文章

相似问题

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