Dynamic columns from 2 joined tables
-
I have 2 pivot tables to be joined from SQL. I have the 2 tables and I have joined then with the following linq, and I even got the result I expect (eventually).
var query = from Lmt in dtLimit.AsEnumerable()
join Ut in dtUtil.AsEnumerable()
on Lmt.Field("LimitID") equals
Ut.Field("LimitID")
select new
{
LimitID = Lmt.Field("LimitID"),
LimitName = Lmt.Field("LimitName"),
Element = Lmt.Field("Element"),
Limit = Lmt.Field("Limit"),
Amount = Ut.Field("Amount"),
Util = Ut.Field("Util")
};The problem is I have 1 or more columns for both dtLimit and dtUtil that are created using a pivot and are therefore dynamic. I can identify the names and data types of the columns at runtime but have no idea how to add them to the above query. I would even settle for ALL columns from the 2 datatables as I would then hide the DGV columns I did not want.
Never underestimate the power of human stupidity RAH
-
I have 2 pivot tables to be joined from SQL. I have the 2 tables and I have joined then with the following linq, and I even got the result I expect (eventually).
var query = from Lmt in dtLimit.AsEnumerable()
join Ut in dtUtil.AsEnumerable()
on Lmt.Field("LimitID") equals
Ut.Field("LimitID")
select new
{
LimitID = Lmt.Field("LimitID"),
LimitName = Lmt.Field("LimitName"),
Element = Lmt.Field("Element"),
Limit = Lmt.Field("Limit"),
Amount = Ut.Field("Amount"),
Util = Ut.Field("Util")
};The problem is I have 1 or more columns for both dtLimit and dtUtil that are created using a pivot and are therefore dynamic. I can identify the names and data types of the columns at runtime but have no idea how to add them to the above query. I would even settle for ALL columns from the 2 datatables as I would then hide the DGV columns I did not want.
Never underestimate the power of human stupidity RAH
Well I fixed this problem, chucked Linq and went back to TSQL, took me a couple of hours to craft the procedure but I got the job done. I took one look at Dynamic Linq, which seems to assume a strongly type dataset every time and shuddered in horror. I despise dynamic TSQL and I think Linq to Dataset leaves a LOT to be desired, I can't imagine trying to debug dynamic Linq. I feel we are creating a support nightmare with linq and Lambda.
Never underestimate the power of human stupidity RAH