I'm trying to get the field (or fields) that is the foreign key for a known type in a MetaTable.
I can get the MetaForeignKeyColumn objects that are of that specific type
var fksOfType = table.Columns.OfType<MetaForeignKeyColumn>().Where(column => column.ParentTable.EntityType == typeof(myType)).Select(column => column.Name);
If my current table has a FK called productId referencing the table Product, then the model creates a MetaForeignKeyColumn "Products" based on that FK. Now I can get the MetaForeignKeyColumn above but I can't find a way to get the actual field
name in the current table that is the fk(productId in this case) to the type Product.
I can get all the MetaColumns that are Foreign Keys
var fkCols = table.Columns.Where(column => column.IsForeignKeyComponent);
and this contains productId but I can't find a way to link it to the type that it is referencing.
Is it possible to link the MetaForeignKeyColumn and it's related MetaColumn ?
Member
3 Points
9 Posts
Get foreign key of specific type from metatable
Sep 08, 2015 05:34 AM|adriang133|LINK
I'm trying to get the field (or fields) that is the foreign key for a known type in a MetaTable.
I can get the
MetaForeignKeyColumn
objects that are of that specific typeIf my current table has a FK called productId referencing the table Product, then the model creates a MetaForeignKeyColumn "Products" based on that FK. Now I can get the
MetaForeignKeyColumn
above but I can't find a way to get the actual field name in the current table that is the fk(productId in this case) to the type Product.I can get all the MetaColumns that are Foreign Keys
and this contains productId but I can't find a way to link it to the type that it is referencing.
Is it possible to link the MetaForeignKeyColumn and it's related MetaColumn ?
DynamicData EntityFramework
All-Star
17916 Points
5681 Posts
MVP
Re: Get foreign key of specific type from metatable
Sep 08, 2015 07:57 AM|sjnaughton|LINK
Once you have the MetaForeignKeyColumn or MetaChildrenColumn they have specific properties that you can reference to get those
i.e. MetaForeignColumn is ForeignKeyNames
MetaChildrenColumn is ColumnInOtherTable
Hope this helps
DynamicData EntityFramework
Always seeking an elegant solution.
Member
3 Points
9 Posts
Re: Get foreign key of specific type from metatable
Sep 09, 2015 06:45 AM|adriang133|LINK
Yes, that was what I was looking for. I can't believe I missed it.
Thank you!
DynamicData EntityFramework