Click here to Skip to main content
Click here to Skip to main content

Converting anonymous types to any type

By , 2 Aug 2009
 

Introduction

This article describes how to handle conversions from an anonymous type to a specific type by using .NET 3.5 extensions. It is especially helpful when using LINQ to SQL to retrieve data in the form of lists and/or arrays.

Problem

With Microsoft LINQ to SQL, you enjoy the ability of using a strong programming language and at the same time having control over your data. Data objects are represented by classes automatically created when you link your data structure to your Visual Studio project via DBML files.

Instead of dividing your attention between SQL and programming, you can now write data retrieving procedures within your Visual Studio programming environment.

At the same time, LINK to SQL sometimes creates some challenges. One of such is the Anonymous type that is returned by LINQ to SQL queries. When you join several database tables in one query, you have to choose how to organize the returning sequence. Often enough, you have to create a sequence that returns a list or an array of Anonymous type objects. Many programmers, myself including, think that it is not the best practice to operate with such anonymous type objects at the business and/or UI layers.

Solution

Let's have a database which consists of two tables: Client and Order.

The Client table has client specific information. In our case, it is Name and AddressID, which obviously point to some depository with addresses info for this client, but that is not our concern now. The Order table has some text describing an order in string format and a ClientID column, which points to an ID of the client who placed the order.

Say, we want to get all the clients info and also how many orders each client made.

Let's see the data by running the following queries:

The Group By query returns the set of rows having ID, Name, Address ID, and Total Orders for all the clients from the Client table. In old days, you would use ADO.NET to retrieve and work with the data.

Addressing the problem

If you want to use LINQ to SQL, you would create a procedure to retrieve the sequence with the required info:

public static List<Client> GetClientsWithTotalOrders()
{ 
   //create DataContext object, use it, discard it:
    using (CodeProjectDataContext db = new GetDataContext())
    {
        //join Client with Order:
        var res = db.Clients
            .Join(
            db.Orders,
            o => o.ID,
            c => c.ClientID,
            (c, o) => new { c }
            )

            //group by Client
            .GroupBy(o => o.c)

            //define output object
            .Select(o => new { ID = o.Key.ID, AddressID = o.Key.AddressID, 
            Name = o.Key.Name, TotalOrders = o.Count() })
            
            //output to List of objects:
            .ToList()
            ;

         //cast the output sequence to List of Clients and return:
         return (List<Client>)res;
    }
}

In this procedure, we join the Client and Order tables and grouped by Client, calculating how many orders the client made. The result is returned in the following format: ID, Address ID, Name, and Total Orders.

Let us add a property into the Client class using the ability to create partial classes, and add any property/methods we want to the classes generated by the Visual Studio Auto Designer:

public int TotalOrders { get; set; }

Now, the Client class has these properties: ID, Name, AddressID, and TotalOrders. A list of objects with all these properties is returned by the LINQ to SQL GetClientsWithTotalOrders() procedure.

But, if you try to compile the procedure, you will get the error:

Error    1    Cannot convert type 'System.Collections.Generic.List<AnonymousType#1>' 
   to 'System.Collections.Generic.List<CodeProject.LinkToSql.Client>'    
   C:\Development\VS2008\Projects\CodeProject\CodeProject\LinkToSql\DbHandlers.cs
       38    23    CodeProject

Unfortunately, there is no way the compiler would recognize that the anonymous type created by the program has the same set of properties as your Client class. That means that you will have to deal with the anonymous List type after you retrieve the data. How can we convert this anonymous type into the Client type?

By writing extensions to deal with anonymous type objects.

I created two extensions to handle this:

public static object ToType<T>(this object obj, T type)
{

    //create instance of T type object:
    var tmp = Activator.CreateInstance(Type.GetType(type.ToString())); 

    //loop through the properties of the object you want to covert:          
    foreach (PropertyInfo pi in obj.GetType().GetProperties()
    {
      try 
      {   

        //get the value of property and try 
        //to assign it to the property of T type object:
        tmp.GetType().GetProperty(pi.Name).SetValue(tmp, 
                                  pi.GetValue(obj, null), null)
      }
      catch { }
     }  

   //return the T type object:         
   return tmp; 
}

This extension allows to convert an anonymous type object into a specified type. If you have an object of an anonymous type and want to covert it to Client type, you need to call this extension:

object obj=getSomeObjectOfAnonymoustype();
Client client=obj.ToType(typeof (Client));

Let us see how it works:

At first, it creates an empty temporary object of Client type using the Activator.CreateInstance() procedure. Then, it loops through every property info of the calling object, gets its value, and re-assigns the value to the corresponding property of the newly created Client object. Finally, it returns the Client type object having all the properties populated from the calling object.

So, for a single object, the problem is solved.

What about a list of such objects? Or arrays?

The second extension I created is to transform a List of Anonymous type objects into a List of a specific type objects:

public static object ToNonAnonymousList<T>(this List<T> list, Type t)
{

   //define system Type representing List of objects of T type:
   var genericType = typeof(List<>).MakeGenericType(t);

   //create an object instance of defined type:
   var l = Activator.CreateInstance(genericType);

   //get method Add from from the list:
   MethodInfo addMethod = l.GetType().GetMethod("Add");

   //loop through the calling list:
   foreach (T item in list)
   {

      //convert each object of the list into T object 
      //by calling extension ToType<T>()
      //Add this object to newly created list:
      addMethod.Invoke(l, new object[] { item.ToType(t) });
   }

   //return List of T objects:
   return l;
}

The first row of the above code is rather interesting:

var genericType = typeof(List<>).MakeGenericType(t);

When we call the MakeGenericType(t) function on typeof(List<>), it substitutes the type of List objects with the type T and returns a Type object representing the List of T objects.

After that, everything is very straightforward:

The activator creates an empty list of T objects. GetType().GetMethod("Add") returns the MethodInfo object which we will use to call method Add() of the newly created list.

Then, we loop through the original list, changing the original type of each element into T by calling our own extension ToType<T>() and finally adding this item into the list of type T. The returned result is the list of type T.

Let us update the procedure with this new extension:

public static List<Client> GetClientsWithTotalOrders()
{
    //create DataContext object, use it, discard it:
    using (CodeProjectDataContext db = new GetDataContext())
    {
        //join Client with Order:
        var res = db.Clients
            .Join(
            db.Orders,
            o => o.ID,
            c => c.ClientID,
            (c, o) => new { c }
            )

            //group by Client
            .GroupBy(o => o.c)

            //define output object
            .Select(o => new { ID = o.Key.ID, AddressID = o.Key.AddressID, 
            Name = o.Key.Name, TotalOrders = o.Count() })
            
            //output to List of objects:
            .ToList()

            //apply extension  to covert into Client
            .ToNonAnonymousList(typeof(Client))
            ;

         //cast the output sequence to List of Clients and return:
         return (List<Client>)res;
    }
}

Calling ToNonAnonymousList(typeof(Client)) converts the List of anonymous type to a List of Client type.

History

  • Added on August 2, 2009
  • When I published this article, I received several comments asking why I converted the anonymous type by calling these extensions when we can just use the following syntax:

    .Select(o => new Client { ID = o.Key.ID, AddressID = o.Key.AddressID, 
       Name = o.Key.Name, TotalOrders = o.Count() })

    As you may notice, this statement creates a Client object rather than an anonymous object.

    If you research forums, you would noticed that many developers complain that this syntax does not work for many LINQ to SQL queries and it returns the following error:

    "Explicit construction of entity type 'xxxxxxxx' in query is not allowed"

    This error is due to a check added by Microsoft. "This check was added because it was supposed to be there from the beginning and was missing. Constructing entity instances manually as a projection pollutes the cache with potentially malformed objects, leading to confused programmers and lots of bug reports for us. In addition, it is ambiguous whether projected entities should be in the cache or change tracked at all. The usage pattern for entities is that they are created outside of queries and inserted into tables via the DataContext and then later retrieved via queries, never created by queries".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ed Guzman
Architect
United States United States
Member
I started as an electronic engineer and moved into programming in 1989, was fascinated by Internet and developed my first web application in 1997.
When Microsoft introduced C# I became its fan and am not disappointed by now.
As for the hobbies, except of course reading, I love skiing and horse riding.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionI got this error when compilingmembercloud1209 May '13 - 10:46 
Hi Ed!
 
Great article you've written!
 
I was trying to use it without success... Frown | :( The compiler says that there is a problem and got me this message: "T does not contain a definition for ToType and no extension method ToType accepting a first argument of type T could be found (are you missing a using directive or an assembly reference?)"
 
This is my code:
 
 
class ConvertidorTiposAnonimos<T>
    {
 
        public static object ToType<T>(this object obj, T type)
        {
 
            //create instance of T type object:
            var tmp = Activator.CreateInstance(Type.GetType(type.ToString()));
 
            //loop through the properties of the object you want to covert:          
            foreach (PropertyInfo pi in obj.GetType().GetProperties())
            {
                try
                {
 
                    //get the value of property and try 
                    //to assign it to the property of T type object:
                    tmp.GetType().GetProperty(pi.Name).SetValue(tmp,
                                              pi.GetValue(obj, null), null);
                }
                catch { }
            }
 
            //return the T type object:         
            return tmp;
        }
 
        public static object ToNonAnonymousList<T>(this List<T> list, Type t)
        {
            //define system Type representing List of objects of T type:
            var genericType = typeof(List<>).MakeGenericType(t);
 
            //create an object instance of defined type:
            var l = Activator.CreateInstance(genericType);
 
            //get method Add from from the list:
            MethodInfo addMethod = l.GetType().GetMethod("Add");
 
            //loop through the calling list:
            foreach (T item in list)
            {
 
                //convert each object of the list into T object 
                //by calling extension ToType<T>()
                //Add this object to newly created list:
                addMethod.Invoke(l, new object[] { item.ToType(t) });
            }
 
            //return List of T objects:
            return l;
        }
    }
 
Hope you can help me.
 
Best regards
GeneralMy vote of 1memberEric Yeoman3 May '13 - 3:50 
Absolutely cannot get this to work.
 
CrMembershipUser ru = user.ToType(typeof(CrMembershipUser));
 
Gives:
Cannot implicitly convert type 'object' to 'CrMembershipAndRoles.Models.CrMembershipUser'. An explicit conversion exists (are you missing a cast?)
GeneralRe: My vote of 1memberEd Guzman3 May '13 - 4:42 
I am sorry for you.
And thank you for down-voting my article because of you cannot make it working.
You can also read others feedback to make sure that you are not only one for whom this is not working.
QuestionHimemberasifjans15 Jun '12 - 23:15 
Hi,
 
Please can you confirm me which namespaces you included for below method.
 
public static object ToNonAnonymousList(this List list, Type t)
 
Hope you are well.
QuestionI need helpmemberMember 879276028 May '12 - 15:54 
Hi. thanks for help us, but I think I need one more help.
 
This is my code:
 
public List RecuperarTodos()
{
BancoEntities banco = new BancoEntities();
 
var retorno = banco.TBTIPOPERGUNTAS
.Select(tp => new { tp.PKCODIGO, tp.DESCRICAO, tp.COMPONENTE })
.ToList()
.ToNonAnonymousList(typeof(TBTIPOPERGUNTA));
 

return (List)retorno;
}
 
When I try to use your code, I get this error
 
"Value cannot be null. Parameter name: Type"
 
I think the problem is when I try to pass the parameter .ToNonAnonymousList(typeof(TBTIPOPERGUNTA))
 
Any ideia?
 
thank you Smile | :)
GeneralThank you so goddamn much! You are a life savior!memberRazor4tx3 Apr '12 - 22:21 
Thank you so much for such a nice article, you have no idea how badly and for long I was looking for something like this. I also did posted a question (Linq: maintain dynamic variable across method calls.[^]) on codeproject, but there was no useful reply...
Again, thanks so much..
and best of luck for your future.
Regards.
GeneralRe: Thank you so goddamn much! You are a life savior!memberEd Guzman4 Apr '12 - 5:25 
You are welcome Smile | :)
Questionvb.net alternativememberMember 833262419 Oct '11 - 4:51 
is there any way to do this in vb.net?? when trying to convert the ToType function mentioned, I get an error message!! I am trying to put the results of my LINQ query into a List and ultimatley have it used by a WCF service. thank you so much in advance!
SuggestionLittle enhancementsmembersgissinger24 Jun '11 - 5:51 
I made some modifications to make you're really good job more Generic and i used less Reflection which costs some performances. Poke tongue | ;-P
 
public static List<TConverted> ToNonAnonymousList<TOriginal, TConverted>(this List<TOriginal> originalList, List<TConverted> convertedList)
    where TOriginal : class
    where TConverted : class
{
    //loop through the calling list:
    foreach (TOriginal item in originalList)
    {
        //convert each object of the list into TConverted object by calling extension ToType<TConverted>()
        //Add this object to newly created list:
        convertedList.Add(item.ToType<TConverted>());
    }
    //return List of TConverted objects:
    return convertedList;
}
 
public static TConverted ToType<TConverted>(this object originalObj)
    where TConverted : class
{
    //create instance of TConverted type object:
    TConverted convertedObj = Activator.CreateInstance<TConverted>();
 
    //loop through the properties of the object you want to covert:          
    foreach (PropertyInfo pi in originalObj.GetType().GetProperties())
    {
        try
        {
            //get the value of property and try to assign it to the property of TConverted type object:
            convertedObj.GetType().GetProperty(pi.Name).SetValue(convertedObj, pi.GetValue(originalObj, null), null);
        }
        catch { }
    }
    //return the TConverted type object:         
    return convertedObj;
}
 
And now i use it this way
 
IEnumerable<People> tiersList = objectContext.People
                                             .Select(f => new
                                             {
                                                 f.Id,
                                                 f.Name,
                                                 f.ForName
                                             })
                                             .ToList()
                                             .ToNonAnonymousList(new List<People>());
 
It works in 3.5 .NET Framework
GeneralRe: Little enhancementsmemberRenshai4 Oct '11 - 11:29 
Hi,
 
What about if we just do
 
objectContext.People
.AsEnumerable()
                                             .Select(f => new
                                             People {
                                                 f.Id,
                                                 f.Name,
                                                 f.ForName
                                             })
                                             .ToList()
 
Why won't this work?
GeneralRe: Little enhancementsmembersgissinger6 Oct '11 - 6:25 
Simply because your code will throw a compilation error like this one
Error	13	Cannot initialize type 'MyEntityModel.People' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
 
To make your code working, you must type
var items = objectContext.People
                         .AsEnumerable()
                         .Select(f => new
                         {
                             f.Id,
                             f.Name,
                             f.ForName
                         })
                         .ToList();
But in this case items type is List<AnonymousType>
 

Using the code snippets of this article, you type
var items = objectContext.People
                         .Select(f => new
                         {
                             f.Id,
                             f.Name,
                             f.ForName
                         })
                         .ToList()
                         .ToNonAnonymousList(new List<People>());
And in this case items type is List<People>
GeneralRe: Little enhancementsmemberRenshai12 Oct '11 - 10:27 
Oh... I'm sorry - I'm using .net 4.0. I remember creating new XElement during a Select in Linq to XML ... so I was kinda worried.
 
I can indeed create any Type inside the Select once I use .AsEnumerable(). Without .AsEnumerable it does throw that exception.
 
The Extension from System.Linq.Enumerable does the conversion
public static IEnumerable AsEnumerable(this IEnumerable source);
public static List ToList(this IEnumerable source);
 
var imports = dc.ExampleType.AsEnumerable()
                           .Select(c => new MyNewType
                           {
                                NAME = c.Name,
                                DESCRIPTION = c.Name + " Unknown ExampleType",
                               LAST_UPDATE_BY = 2,
                               LAST_UPDATE_DATE = DateTime.Now
                           })
                           .OrderBy(c => c.Name.Length)
                           .ThenBy(c => c.Name)
                           .ToList();
           try
           {
               dc.MyNewTypes.InsertAllOnSubmit((List<MyNewType>)imports);
               dc.SubmitChanges();
           }
 
worked like a charm.
Generalworked very well. thank youmemberuandimayur13 Apr '11 - 2:16 
reduce a lot of work and code too.
GeneralRe: worked very well. thank youmembervaswork13 Apr '11 - 3:01 
... me too. Thanks!
GeneralException Details: System.MissingMethodException: No parameterless constructor defined for this object.memberJakob Flygare31 Mar '11 - 23:30 
I get the following error; any ideas?
 
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
 
Source Error:
 

Line 14:
Line 15: //create instance of T type object:
Line 16: var tmp = Activator.CreateInstance(Type.GetType(type.ToString()));
Line 17:
Line 18: //loop through the properties of the object you want to covert:
GeneralRe: Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.membervaswork13 Apr '11 - 3:05 
[bad English.sorry]
 
As I understand, you should implement that kind of constructor. After that everythings are working fine.
 
// Parameterless constructor:
public Client()
{
}
GeneralMy vote of 5memberpratapgowda9 Nov '10 - 1:44 
Great article..
GeneralVB.net version !!memberGurdeep Toor16 Sep '10 - 5:48 
Just wondering if anyone has the chance to do the same in VB !! I tried to convert code but No Luck..
 
Thanks Cry | :((
AnswerRe: VB.net version !!mvpthatraja28 Jan '12 - 5:31 
Check this blog post .NET Code Conversion[^]
thatraja

FREE Code Conversion VB6 ASP VB.NET C# ASP.NET C++ JAVA PHP DELPHI | Nobody remains a virgin, Life screws everyone Sigh | :sigh:

GeneralWorked for me..!!memberGurdeep Toor16 Sep '10 - 5:46 
Hey Ed
 
Thanks for the code.. worked for me like a charm.. I had to covert the linq result into Data table and then list of Object now The Datatable step is eliminated with help of this code..
 
Cheers..!! Smile | :)
GeneralToType method is not being picked upmemberkale333327 Oct '09 - 1:08 
Probably because I have not go the hang of extension methods, the ToType() method is not being picked up in the ToNonAnonymousList method. "T does not contain a definition for ToType() and no extension method "ToType" accepting a first arguement of type T
GeneralRe: ToType method is not being picked upmemberkale333327 Oct '09 - 1:30 
Ok, you put it in a static class
QuestionWhy do you need the type argument?memberGer20014 Aug '09 - 6:22 
Great article, btw. Opened my eyes up to a whole new area of .NET and C#.
 
But can't ToType be simplified?
 
        public static T ToType<T>(this object obj)
        {
           //create instance of T type object:
           var tmp = Activator.CreateInstance(typeof(T)); 
                            
           //loop through the fields of the object you want to covert:          
           foreach (System.Reflection.FieldInfo fi in obj.GetType().GetFields() )
           {
                try 
                {   
                    tmp.GetType().GetField(fi.Name).SetValue(tmp,fi.GetValue(obj));
                }
                catch { }
            }  
                            
            //return the T type object:         
            return (T)tmp; 
        }    
 
(Here I changed to copy fields)
 
Now I can "convert" any class A object to class B with:
 
B bb = aa.ToType();
AnswerRe: Why do you need the type argument?memberGer20014 Aug '09 - 6:24 
opps the angle brackets disappeared.
To convert I can use:
        B bb = aa.ToType();

GeneralRe: Why do you need the type argument?memberGer20014 Aug '09 - 6:26 
arrrg!
B b = aa.ToType (left angle bracket) B (right angle bracket) ();
JokeRe: Why do you need the type argument?memberTobiasP5 Aug '09 - 3:24 
It seems you had some problems with the editor! Smile | :) You can press the < and > buttons on top of the message text box when you write a new message to insert the correct characters, or write the HTML entities &lt; and &gt; manually to insert the less-than and greater-than signs. I hope this helps.
AnswerRe: Why do you need the type argument?memberMaxxi863 Mar '10 - 5:09 
The hole point is to have an anonymous type and convert it to a strong type.
So you cannot get the strong type from the anonymous of course.
GeneralGood StartmemberDewey2 Aug '09 - 8:42 
This does address the simplier situations, and thus, it's a good start.
 
There are other projects on Codeplex that are more effective, and this project is in the class of reflective object mappers.
 
Where your project will fail is on complex types, where you would need to do recursion to get all the values right, and when the properties are of a different type, you have no conversion to produce a correct result.
 
Still, this works for the case in which you've designed it, and that, in the final analysis is all that's required. I'm just informing users of some of the limitations and additional options.
 
Keep up the good work.
GeneralRe: Good StartmemberEd Guzman3 Aug '09 - 3:41 
I wrote this extension for a very practicable issue which any developer can meet in every day practice and actually many are trying to find the solution. It was not intended to handle the complex data types, of course Smile | :)
Definitely it is worth trying to extend it for complex types and to research how it handles recursions.
Thank you for the comments. They just gave my some perspectives and when I have time I will address this.
GeneralI think I missed somethingmemberspoodygoon2 Aug '09 - 2:49 
I think I missed something what your saying is that you don't know what the data type is of the data you are retrieving? I don't have much experience with LINQ so that is probably why I'm confused. I just can't think of a situation where I would not know the type of the data that I am asking for but that is most likely a lack of experience on my part.
 
Thanks
GeneralRe: I think I missed somethingmemberEd Guzman2 Aug '09 - 3:26 
When you use
.select(new {ID=o.ID,.......})
.ToList();
it creates List of anonymous type objects.
Of course you know which properties you placed into every object but the Type of it is anonymous.
When you use this list in your calling object(grid, repeater), say you assign DataSource for the grid, your compiler does not know the type of the List. It is not defined explicitly. During development your intellesense will not prompt you on those properties and you need to write some code to get those properties from the anonymous object.
GeneralRe: I think I missed somethingmemberspoodygoon2 Aug '09 - 7:01 
Ok now I get it thanks.
GeneralMy vote of 5memberMember 36659371 Aug '09 - 23:36 
Really smart approach! It perfectly solved one big issue I was facing at.
Thank you!
GeneralRe: My vote of 5memberEd Guzman2 Aug '09 - 2:35 
I am glad it helped you.
GeneralMy vote of 5, toomemberMidax5 May '10 - 5:51 
Tks
.

GeneralEasier way.memberMember 272709831 Jul '09 - 23:29 
Are you reinventing the wheel?
 
You can instantiate known type inside linq query and there is no need to do "conversion" from anonymous types.
 
Instead of this (which generates anonymous type):
 
select new { p1 = v1, p2 = v2 }
 
use this syntax to generate list of Client instances:
 
select new Client() { p1 = v1, p2 = v2 }
GeneralRe: Easier way.memberEd Guzman1 Aug '09 - 2:07 
In many cases you cannot use "select new Client" syntax.
There is a runtime error "Explicit construction of entity type 'xxxxxxxx' in query is not allowed"
This error is due to a check added by Microsoft:
"This check was added because it was supposed to be there from the beginning and was missing. Constructing entity instances manually as a projection pollutes the cache with potentially malformed objects, leading to confused programmers and lots of bug reports for us. In addition, it is ambiguous whether projected entities should be in the cache or changed tracked at all. The usage pattern for entities is that they are created outside of queries and inserted into tables via the DataContext and then later retrieved via queries, never created by queries".
 
In these cases you can create your own class and use it in the constructor or use my work around
Thank you
GeneralRe: Easier way. [modified]memberMember 27270982 Aug '09 - 10:34 
Hmm... I see problem here...
 
You are retrieving objects of type Client and Order. Then you group results (Clients and Orders) and in there you create count aggregate of orders (o.Count()) by client. This result is anonymous. Then you convert these anonymous objects back to object of type Client. I see shortcoming here. Result type actually is not type of Client, but you force it to be (it is "client-order group-aggregate").
 
So, how about one additional class, like "ClientOrder" to represent group-aggregate result item? I think that this non-anonymous type construction "... new ClientOrder() { p1 = v1, p2 = v2 } ..." should work fine? I don't know does it work but I see that more clear approach. Only drawback is that one additional class must be written but I see this more appropriate choice than adding TotalOrders property to Client type because it has nothing to do with LinqToSql (it is not database table column).
 
modified on Sunday, August 2, 2009 4:40 PM

GeneralRe: Easier way.memberMarc Brooks4 Aug '09 - 9:03 
Indeed, the correct thing is to project to a ClientWithOrderCount class that specifically maps to the projection of the query. Then you can simply project into a class instance as desired.
 
http://musingmarc.blogspot.com

GeneralRe: Easier way.memberMr Yossu29 Jul '10 - 10:40 
Any idea how to do this? I tried it and got all sorts of errors. I'm actually getting very frustrated with this whole business. MS have provided a first-class framework for doing the queries and binding them to controls, but the whole thing seems to fall down badly when you want to get at the data from inside the control.
 
I would be grateful if you could show how to project to a ClientWithOrderCount class, because I couldn't get it to work.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 2 Aug 2009
Article Copyright 2009 by Ed Guzman
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid