locked
AddLink is a pain ... please change this.... RRS feed

  • General discussion

  •  

    Hi,

     

    We start to use intensively Entity Data Model and Data Services and we love the big pictures.

     

    One thing is really made us sad is the AddLink method.

     

    We have a pretty all object oriented data model with each entity knowning each navigation property but add link need a string property argument which is really strange or I miss something.

     

    Why to not use MyEntity.MyNavigation1.Name or ToNameString or ??? but please remove any non object argument.

     

    ex:

    //create new log entry

    ....

    Ctx.AddToLog_LOG(log);

    //Add foreign key values

     

    Ctx.AddLink(actQuery, "Logs_LOG", log);

    Ctx.AddLink(staFromQuery, "Logs_From_LOG", log);

     

    //Could be

    Ctx.AddLink(actQuery, log.Logs_LOG, log);

    Ctx.AddLink(staFromQuery, log.Logs_From_LOG, log);

     

    Can we imaginate a situation where the property would be different of the real navigation property name ?

     

    my 2ct

    anybody with me on this ?

     

    Thanks

    Regards

     

    -Vince

    Monday, July 28, 2008 3:01 PM

All replies

  •  

    Hi Vince,
     Thanks for the feedback.
     For V1 , we wanted to give you POCO access to the data classes. Although we could infer the relation based on the type of the navigation property , this would break scenarios where we have more than 1 navigation properties of the same type and belonging to the same entity Set.
    Consider this entity ,

    Code Snippet

    public class Customer{
    public List<Orders> CashPurchases{get;set;}
    public List<Orders> CreditCardPurchases{get;set;}
    }

     

     

    if you do an AddLink with just an instance of Orders, we would have to guess which navigation property we have to add the link to .

    Code Snippet

    Customer newCustomer = new Customer();
    Orders cashPurchase = new Orders();
    Orders creditCardPurchase = new Orders();

    context.AddLink( newCustomer , "??", cashPurchase);

     

     

    //In the above case , trying to guess the name of the association will land us in hot water as we dont know which navigation property you intended . We cant go the other way around and try to use the instance of Orders to guess the name of the association with respect to Customers as Orders may have other associations of type Customers and we dont know which one you intended.

    If you do not wish to use the string to remember the association name , you can move that to a separate resource file and have all your strings localized in one place.

    Consider this ..

    Code Snippet

    public class StoreConstants{

    public static string Customers_To_CashPurchases  ="CashPurchases";
    public static string Customers_To_CreditCardPurchases  ="CreditCardPurchases";

    }

     

     

    and then in your code ,


    Code Snippet

    Customer newCustomer = new Customer();
    Orders cashPurchase = new Orders();
    Orders creditCardPurchase = new Orders();

    context.AddLink( newCustomer , StoreConstants.Customers_To_CashPurchases , cashPurchase);
    context.AddLink( newCustomer , StoreConstants.Customers_To_CreditCardPurchases , creditCardPurchase );

     

     


    Hope this helps

    Monday, July 28, 2008 3:41 PM
    Moderator