Passing around anonymous types

by Marius Gheorghe 3. September 2007 17:32
You can't pass around (or return from a function) a anonymous type in C# 3.0 .If you want to do that you have to ""get"" the entire type. I see 2 particular problems with either of these approaches :
- get the entire type instance

var f = from d in ds
where d.b > 56
select d;

Let's suppose that ""d"" is a mapped ""Developer"" entity with 20 fields. Even if you need 2 fields you are forced to retrieve all 20 fields.

- get a subset of data

var f = from d in ds
where d.b > 56
select new { d.a, d.u };


In this case you have a anonymous type which you can't pass around so you'll need to make the binding/extra logic in the same function. This is really bad for separation of concerns.

Tags:

dotNET

Comments are closed

marius gheorghe

developer, dad, gamer

Contact me

My Resume

Favourite Tools