获取所有引用列到linq中的引用列 [英] Get all referencing columns to a referenced column in linq
问题描述
$ p $ c $ SELECT
FROM INFORMATION_SCHEMA
WHERE CONSTRAINT_TYPE ='FOREIGN KEY'
SELECT [name] as FKeyName,
(SELECT o1。[name] from sys.objects o1 where
o1。[作为ParentTableName,
(SELECT o2。[name] from sys.objects o2 where
o2。[object_id] = fk.referenced_object_id)作为ReferencedTableName
FROM sys。 foreign_keys fk
$ b $ p
$ b如果你真的需要列名,请打开
sp_helpconstraint <
在设计者方面,dbml文件是xml ...查找Database.Table.Type.Association
Say you have a Table named Sales with a SalesOrderId. Then you have two tables SalesOrderHeader and SalesReport that reference SalesOrderId. Starting from the Sales Tables and SalesOrderId, is there any way to figure out those two table reference it using linq? I want to add a Debug.Assert to my code so that I can update that piece of code whenever there is another foreign key constraint added against a column.
解决方案 On the database side, these might help:
SELECT *
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE = 'FOREIGN KEY'
SELECT [name] as FKeyName,
(SELECT o1.[name] from sys.objects o1 where
o1.[object_id] = fk.parent_object_id) as ParentTableName,
(SELECT o2.[name] from sys.objects o2 where
o2.[object_id] = fk.referenced_object_id) as ReferencedTableName
FROM sys.foreign_keys fk
If you really need the column names, pop open sp_helpconstraint
in the system stored procedures and extract the logic from there.
On the designer side, the dbml file is xml... look for Database.Table.Type.Association
这篇关于获取所有引用列到linq中的引用列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!