Get foreign key of specific type from metatable RRS feed

  • Question

  • User1098690930 posted

    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 ?


    Tuesday, September 8, 2015 5:34 AM


All replies