简体   繁体   English

EF6和预生成的视图

[英]EF6 and pre-generated views

I am using EF code first method in my project. 我在我的项目中使用EF代码优先方法。 Recently I updated EF version of my project to EF 6 using Package Manager Console. 最近,我使用软件包管理器控制台将项目的EF版本更新为EF 6

All of my entities are inherited from a BaseEntity class as a super class : 我所有的实体都从BaseEntity类继承为超类:

public abstract class BaseEntity
{
    public virtual int Id { get; set; }


    States _state;

    [NotMapped]
    public States State { get; set;}

    public enum States
    {
        Unchanged,
        Added,
        Modified,
        Deleted
    }
    ....  
}

And also I don't add the BaseEntity in my DbContext , the program run without any problem, but since I added pre-generated views to my project using EF6 CodeFirst View Generation T4 Template for C# , when I generate the views there is no problem, but when I run my project, I got following error: 而且我也没有在我的DbContext添加BaseEntity ,程序运行没有任何问题,但是由于我使用C#的EF6 CodeFirst View Generation T4模板向项目中添加了预生成的视图,因此在生成视图时没有问题,但是当我运行项目时,出现以下错误:

The current model no longer matches the model used to pre-generate the mapping views, as indicated by the ViewsForBaseEntitySets786b989cf4a349108a38357765a23070.MappingHashValue property. 当前模型不再匹配用于预生成映射视图的模型,如ViewsForBaseEntitySets786b989cf4a349108a38357765a23070.MappingHashValue属性所指示。 Pre-generated mapping views must be either regenerated using the current model or removed if mapping views generated at runtime should be used instead. 如果要改用运行时生成的映射视图,则必须使用当前模型重新生成或删除预先生成的映射视图。 See http://go.microsoft.com/fwlink/?LinkId=318050 for more information on Entity Framework mapping views. 有关实体框架映射视图的更多信息,请参见http://go.microsoft.com/fwlink/?LinkId=318050

Does know anyone where is the problem? 知道有人在哪里吗? Or at least what is the way to find the problem? 或者至少是找到问题的方法是什么?

Most likely you are hitting this bug. 您最有可能遇到了这个错误。 The title suggests it was fixed in EF 6.1.0 alpha - can you try this release and confirm? 标题表明它已在EF 6.1.0 alpha中修复-您可以尝试此发行版并进行确认吗? If you still see the error can you create a bug on https://entityframework.codeplex.com/WorkItem/Create ? 如果仍然看到错误,是否可以在https://entityframework.codeplex.com/WorkItem/Create上创建错误? Be sure to attach your model - without the model it will be very hard to fix this bug. 确保附加模型-如果没有模型,将很难修复此错误。 Another approach to take is to use a different project of mine - interactive EF view generation. 采取的另一种方法是使用我的另一个项目-交互式EF视图生成。 You can find more details here and here . 您可以在此处此处找到更多详细信息。 The project is available on NuGet . 该项目在NuGet上可用。 Finally, is your model really that big that you need to use pre-generated views? 最后,您的模型真的需要使用预先生成的视图那么大吗? View generation has been greatly improved in EF6 (and more improvements are coming in 6.1) so I am curious if you really see a significant improvement in your application start up time when using pre-generated views. 在EF6中,视图生成已得到了很大的改进(6.1中将进行更多的改进),所以我很好奇您在使用预生成的视图时是否真的看到应用程序启动时间有了显着改善。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM