如何将视图链接到VB.NET代码中的模型

发布于 2025-01-22 20:09:39 字数 578 浏览 2 评论 0原文

我已经使用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中,指定的类型成员“ recherCheeXoint”不支持实体。仅支持初始化器,实体成员和实体导航属性。

如果我删除了我的错误,说我不同样的户口和财产...另外,我如何在idrecherche上映射rechercheexhich,

谢谢您的帮助

I've an old programm with edmx. Inside this one, I've linked a class (Table) To a View (Table/filter on a value of a column)
I want migrate this project to code first.
I copy/paste the project delete edmx file and generate models from an existing database.
All is good except this link.

<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

But When I try to use function of automatical sort/filter using expression
I've error : The specified type member 'RechercheJoint' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

If I removed I error saying I don't same comumn and property... Also , How Can I stipulate RechercheJoint is mapped on IdRecherche

thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温暖的光 2025-01-29 20:09:39

最终使用ModelBuilder,我可以加入我的视图和桌子,例如在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)

Finally Using modelbuilder, I can join my view and my table like in 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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文