Generic/anonymous result from datacontext RRS feed

  • Question

  • i'm operating Stored procedures from a data context.
    each Stored procedure has to be operated according to a certain checkbox set on the GUI.

    my problem is that i'm trying to make a simple function to handle the result of the SP,which turns the result to list and present it.
    but i can't find anything common between the result interfaces because the ISingleResult is typed and also the List must be typed!
    i tried generics and even var , but i can't even create a simple common function that handles the results.

    for example:

    if Checkbox1 is set:

    System.Data.Linq.ISingleResult<GetGetHelloResult> res = MyDataContext.GetHello();
    if Checkbox2 is set:
    System.Data.Linq.ISingleResult<GetGetWorldResult> res = MYDataContext.GetWorld();

    is there a common interface to the results? so i can just do:

    CommonInterface res;
    switch (GUI)
    case :  res = MyDataContext.GetHello();
    case:  res = MyDataContext.GetWorld();
    Coomontype list = res.tolist();

    Monday, July 20, 2009 9:02 AM


  • You can use IEnumerable.   ISingleResult<T> is an IEnumerable<T> which is an IEnumerable.   However, the ToList method is not defined for IEnumerable.  You could instead make either a List of object's or an ArrayList.

    IEnumerable res;

    switch (GUI)
       case xxx: res = MyDataContext.GetHello();
       case yyy: res = MyDataContext.GetWorld();

    var list = res.Cast<object>().ToList();


    var list = new ArrayList(res);

    Wayward LINQ Lacky
    Monday, July 20, 2009 3:10 PM