簡體   English   中英

如何將視圖鏈接到 vb.net 代碼中的 model 首先

[英]How to link a view to a model in vb.net code First

我有一個帶有 edmx 的舊程序。 在這個里面,我已經將一個 class(表)鏈接到一個視圖(表/列值的過濾器)我想首先將這個項目遷移到代碼。 我復制/粘貼項目刪除 edmx 文件並從現有數據庫生成模型。 除了這個鏈接,一切都很好。

<Table("JoinAffectation")>
partial public Class JointAffectation
 public property Id as Long
 public IdRecherche as Integer 'the link with my view
 <NotMapped>
 <ForeignKey("Id")>
 PUBLIC OVERRIDABLE PROperty RechercheJoint as ViewRechercheJoint

但是,當我嘗試使用 function 的自動排序/過濾器使用表達式時,出現錯誤:LINQ 中不支持指定的類型成員 'RechercheJoint' 到實體。 僅支持初始值設定項、實體成員和實體導航屬性。

如果我刪除了我的錯誤說我不相同 comumn 和屬性...另外,我如何規定 RechercheJoint 映射到 IdRecherche

感謝您的幫助

最后使用模型構建器,我可以像在 edmx 中一樣加入我的視圖和表

<Table("JointAffectation")>
Partial Public Class JointAffectation
  Public Property Id As Long
  Public Property IdTypeJoint As Long
  Public Property IdRecherche As Integer
  Public Overridable Property JointType As JointType

  <ForeignKey("Id")>
  Public Overridable Property RechercheJoint As ViewRechercheJoint

End Class

<Table("ViewRechercheJoint")>
Partial Public Class ViewRechercheJoint
  <Key>
  <DatabaseGenerated(DatabaseGeneratedOption.None)>
  Public Property Id As Integer

  <StringLength(50)>
  Public Property Libelle As String

  <ForeignKey("IdRecherche")>
  Public Overridable Property JointAffectations As ICollection(Of JointAffectation)

End Class 

modelBuilder.Entity(Of JointAffectation)() _
        .HasRequired(Function(e) e.RechercheJoint) _
        .WithMany(Function(e) e.JointAffectations) _
        .HasForeignKey(Function(e) e.IdRecherche)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM