我有一個帶有 edmx 的舊程式。在這個里面,我已經將一個類(表)鏈接到一個視圖(表/過濾列的值)我想首先將此專案遷移到代碼。我復制/粘貼專案洗掉 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
但是,當我嘗試使用運算式使用自動排序/過濾功能時,出現錯誤:LINQ to Entities 不支持指定的型別成員“RechercheJoint”。僅支持初始化程式、物體成員和物體導航屬性。
如果我洗掉了我的錯誤,說我的 comumn 和屬性不同......另外,我如何規定 RechercheJoint 映射到 IdRecherche
感謝您的幫助
uj5u.com熱心網友回復:
最后使用模型構建器,我可以像在 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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/467021.html
上一篇:將書寫方向保持在圓圈內
