Hi!
I tried to make some code, which takes any table/entity and any column/field in it and list all data in that column (i.e. into dropdown). It is very easy to make it in SQL
SELECT DISTINCT column FROM table;
but we have year 2009, why to make it this simple. Let's try LINQ. This is how I ended:
LinqMetaData md = new LinqMetaData();
var p = Expression.Parameter(Column.Table.EntityType, "row");
IQueryable<string> q =
md.BookingWithAirports.Select<BookingWithAirportsEntity, string>(Expression.Lambda<Func<BookingWithAirportsEntity, string>>(Expression.Property(p, "CodeAirportArrival") , new ParameterExpression[] { p }));
(Column.Table.EntityType is the type of the entity = BookingWithAirportsEntity. CodeAirportArrival is the name of one column in this table)
The problem is, there are two BookingWithAirportsEntity left hardcoded, which I cannot get rid of. I think I could make another lambda for Select (though it is pretty difficult because it is generic method). Then I could use
table.GetQuery().Provider.CreateQuery(theWholeExpressionsPart);
Where table is MetaTable from DynamicData.
But all this is rather really difficult to tie together. I am a bit confused, because the SQL is so simple and other ways seems almost imposible.
So is this at least a good approach? (Lambda expressions)
BTW: How can I make it in plain LLBL?
I mean I have the table, the column and want to fetch only distinct values from one column?
I suppose I will do SP for this, I am just too tired