zoukankan      html  css  js  c++  java
  • 在EF4.0中建立表与视图之间的关联(create association between TABLE and VIEW in EF4.0)

    建立表和视图的脚本
    create table Table1
    (
        Id    
    int identity(1,1not null,
        Name    
    nvarchar(20not null,
        DepartmentId    
    int not null,
        Attachment1    
    image,
        Attachment2 
    image,
    constraint pk_Table1 primary key(Id)
    )
    go

    create view Table1Simple
    as
      
    select id, Name, DepartmentCode, DepartmentName
        
    from Table1 T
        
    join sysDepartment D on T.DepartmentId=D.DepartmentId
    go

    将上面脚本建立的Table1表和Table1Simple视图添加到edm设计器中,然后添加一个Association,并将添加的Association关联到Table1Simple视图,问题出现了:

    Error 3021: Problem in Mapping Fragment starting at line 72: Each of the following columns in table Table1Simple is mapped to multiple conceptual side properties: Table1Simple.id is mapped to <Table1Simple_Table1.Table1.id, Table1Simple_Table1.Table1Simple.id> 

    恭喜你,这是EF4.0的一个BUG,而据官方说会在下一个发行版本中修正,值得高兴的是至少我们还有办法手工修正它:

    用XML编辑器打开emdx文件,找到新建的Association,作如下修正:

    <Association Name="Table1Simple_Table1">
      
    <End Type="Cohl.Model.Table1" Role="Table1" Multiplicity="1" />
      
    <End Type="Cohl.Model.Table1Simple" Role="Table1Simple" Multiplicity="1" />
    </Association>

    <!--我们添加一个引用约束如下所示:-->

    <Association Name="Table1Simple_Table1">
      
    <End Type="Cohl.Model.Table1" Role="Table1" Multiplicity="1" />
      
    <End Type="Cohl.Model.Table1Simple" Role="Table1Simple" Multiplicity="1" />
      
    <ReferentialConstraint>
        
    <Principal Role="Table1"><PropertyRef Name="id"/></Principal>
        
    <Dependent Role="Table1Simple"><PropertyRef Name="id"/></Dependent>
      
    </ReferentialConstraint>
    </Association>


     参考:http://blogs.msdn.com/b/adonet/archive/2008/12/05/table-splitting-mapping-multiple-entity-types-to-the-same-table.aspx

  • 相关阅读:
    ORACLE 定时执行存储过程
    Java 基于spring 暴露接口 供外部调用
    java 从jsp页面传集合给controller
    Java 后台验证的工具类
    Xcode12真机/模拟器运行项目非常慢的解决方式
    苹果手机系列 安全区高度/设置粗体高度不正常
    Xcode 官方下载地址
    OC UICollectionView 滚动完全显示item
    cocospod 更新到指定版本及其问题
    OC 一张图片填充满整个导航栏(包含X系列)
  • 原文地址:https://www.cnblogs.com/wiseant/p/1758190.html
Copyright © 2011-2022 走看看