“从数据库更新模型"; [英] "Update model from database"

查看:37
本文介绍了“从数据库更新模型";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio,并在基于MVC的应用程序上工作.我正在尝试向模型添加一些表.我使用了从数据库更新模型"选项.新表出现在我的edmx文件中.我已经重建了解决方案,但是缺少新表的类.每当我想添加新表时,是否有任何技巧可以生成类?还是我必须手动进行?当我将代码生成策略"设置为默认"时,我收到数百个与此错误类似的错误 Error 117类型'Mvc4.Models.DPR_MM'已经包含'DPR_TS'的定义.
我已经删除了整个模型.在搜索 DPR_MM 的整个解决方案时,我得到了以下结果:查找所有"DPR_MM",子文件夹,查找结果1,整个解决方案,"

I 'm using Visual Studio and working on an app based on MVC. I'm trying to add some tables to my model. I have used option "Update model from database". The new tables appeared in my edmx file. I have rebuilt my solution but the classes for new tables are missing. Is there any trick to generate the classes every time i wanna add new tables? Or do i have to do it manually? When I set 'Code Generation Strategy' to 'Default' I'm getting hundred of errors similar to this one Error 117 The type 'Mvc4.Models.DPR_MM' already contains a definition for 'DPR_TS'.
I have removed the whole Model. While searching the whole solution for DPR_MM I'm getting these results: Find all "DPR_MM", Subfolders, Find Results 1, Entire Solution, ""

  C:\\Mvc4\Controllers\HomeController.cs(41):                    var DPR_MM = from d in ctx.DPR_MM
  C:\\Mvc4\Controllers\HomeController.cs(45):                    var arr = new object[DPR_MM.Count()];
  C:\\Mvc4\Controllers\HomeController.cs(47):                    foreach (var d in DPR_MM)
  C:\\Mvc4\Models\Model1.edmx(9):          <EntitySet Name="DPR_MM" EntityType="Model.Store.DPR_MM" store:Type="Tables" Schema="QF" />
  C:\\Mvc4\Models\Model1.edmx(45):        <EntityType Name="DPR_MM">
  C:\\Mvc4\Models\Model1.edmx(366):          <EntitySet Name="DPR_MM" EntityType="Model.DPR_MM" />
  C:\\Mvc4\Models\Model1.edmx(389):        <EntityType Name="DPR_MM">
  C:\\Mvc4\Models\Model1.edmx(715):          <EntitySetMapping Name="DPR_MM">
  C:\\Mvc4\Models\Model1.edmx(716):            <EntityTypeMapping TypeName="Model.DPR_MM">
  C:\\Mvc4\Models\Model1.edmx(717):              <MappingFragment StoreEntitySet="DPR_MM">
  C:\\Mvc4\Models\Model1.edmx.diagram(8):        <EntityTypeShape EntityType="Model.DPR_MM" Width="1.5" PointX="0.75" PointY="0.75" IsExpanded="true" />
  Matching lines: 11    Matching files: 3    Total files searched: 168

所以我看不到任何DPR_MM类.我在做什么错了?

So I don't see any DPR_MM class. What I am doing wrong?

推荐答案

编辑

现在我知道您遇到了错误,请查看生成的代码(您甚至可以对类DPR_MM进行解决方案搜索以找到该类的所有实例).我猜想您的项目中已经有一个类Mvc4.Models.DPR_MM,该类已经具有DPR_TS作为成员,并且代码生成会看到该类并且不会生成另一个类,如下所示:

Now that I know you are getting an error, look at the generated code (you could even do a solution search for your class DPR_MM to find all instances of this class). I would guess you have a class Mvc4.Models.DPR_MM in your project that already has DPR_TS as a member and code generation sees that and won't generate another one, kind of like the following:

public partial class DPR_MM : EntityObject
{
    public global::System.Int32 DPR_TS
    {
    ...
    }
}

public partial class DPR_MM : EntityObject
{
    //maybe code generation fails because it doesn't want to do this a second time knowing it would be ambiguous 
    public global::System.Int32 DPR_TS  
    {
    ...
    }
}

除非存在一些数据库或名称空间问题,否则您应该始终能够生成新模型,因此请确保没有多余的文件,如@Mamu所说.或者您可以谷歌搜索它:
首次点击
另一个回答

You should always be able to generate a new model unless there is some database or namespace problem so make sure you don't have extra files laying around like @Mamu says. Or you could just google it:
first hit
another answer





初始答案

进行构建.然后,您应该根据从数据库更新模型"时选择的表查看所有新类(显然,从数据库更新模型"时必须选择新表)

Do a build. You should then see all your new classes based on the tables you selected when you "updated model from database" (obviously you have to select the new tables when "updating model from database")

这篇关于“从数据库更新模型";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆