gpt4 book ai didi

c# - Linq to Sql 如何获取一个实体的所有外键字段

转载 作者:太空宇宙 更新时间:2023-11-03 13:58:24 25 4
gpt4 key购买 nike

我想获取实体表中的所有外键列。例如:

class User
{
Id {get;set;}
Name {get;set;}
ColumnWithForeignKey1Id{get;set;}
ColumnWithForeignKey2Id{get;set;}
ColumnWithForeignKey3Id{get;set;}
}

结果应该是这样的:

  • ColumnWithForeignKey1Id
  • ColumnWithForeignKey2Id
  • ColumnWithForeignKey3Id

最佳答案

在 xml 编辑器中打开您的 dbml 文件,您将看到外键:

  <Association Name="Table1_Table2" Member="Table1" ThisKey="Table2ID" OtherKey="ID" Type="Table2" IsForeignKey="true" />

打开 designer.cs 文件,您会看到外键实现为具有 System.Data.Linq.Mapping.AssociationAttribute 的属性,该属性由 EntityRef< 支持EntitySet

如果您正在使用反射,请查找 AssociationAttribute


如果您不使用设计器生成建模类,请使用您自己的属性修饰这些属性,以便您可以找到它们。

关于c# - Linq to Sql 如何获取一个实体的所有外键字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com