Type or namespace of 'ModelBuilder' cannot be found (are you missing a using directive or assembly reference?)

╄→гoц情女王★ 提交于 2020-01-13 08:51:48

问题


In step 7 of the ASP.MVC 3 Tutorial, it introduces the 'ModelBuilder' type. I'm using ASP.Net 4, MVC 3, and EF 4.1, and I get the red squiggly lines under the 'ModelBuilder' type. It can't find the type. Has that type name changed? What reference should I add to use it?

using System;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
...

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Movie>().Property(p => p.Price).HasPrecision(18, 2);
    }

回答1:


The name changed from CTP5 to EF 4.1. This thing is now called DbModelBuilder.




回答2:


According to MSDN that is still a good class. It's located in Microsoft.Data.Schema.SchemaModel.

I just tested this and I had no problems. You need to make sure you add a reference in your project to the the assembly listed at the MSDN link. The assembly is Microsoft.Data.Scheme.dll. Then in your code you need a using Microsoft.Data.Schema.SchemaModel.



来源:https://stackoverflow.com/questions/5450463/type-or-namespace-of-modelbuilder-cannot-be-found-are-you-missing-a-using-dir

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!