none
how to get relationship data from MetaAssociation RRS feed

  • Question

  • hi all

    i want to get the FK and PK details in relationship in the database from MetaAssociation class
    i try to use this properties :  ThisKey  ThisMember  OtherMember OtherKey .
    but i can't  get the tables name and columns name for FK and PK .

    can anyone help me how to do this ?

    thank you .
    Monday, August 18, 2008 7:56 AM

Answers

  • Here is some sample code that should help explain things:

     

    MetaType mainType = db.Mapping.GetMetaType(typeof(MyTable));
    Console.Write("Primary key is '");
    foreach (MetaDataMember member in mainType.IdentityMembers)
        Console.Write(member.MappedName + " ");
    Console.WriteLine("'");

    foreach (MetaAssociation association in mainType.Associations) {
        Console.Write("Association to '" + association.OtherType.Name + "' is '");
        foreach (MetaDataMember member in association.ThisKey)
            Console.Write(member.Name + " ");
        Console.Write("' = '");
        foreach (MetaDataMember member in association.OtherKey)
            Console.Write(member.Name + " ");
        Console.WriteLine("'");
    };


     

    Hope that helps,

     

    [)amien

    Monday, August 18, 2008 10:18 PM
    Moderator