I use LINQ Dynamic Query Library https://weblogs.asp.net/scottgu/dynamic-linq-part-1-using-the-linq-dynamic-query-library It works great for querying to query fields optionally
IQueryable GetSource( DataTable t, String str)
{
//Working str = "new (T[\"ss\"] as ss,T[\"xx\"] as xx )"
//Not Working str = "new (T[\"ss\"] as ss, T[\"xx\"] as xx , T[\"ss\"] T[\"xx\"] as yy)"
return (from T in t.AsEnumerable()
select new{T}).AsQueryable().Select(str);
}
But when I try to Operations such as (addition - multiplication - division - merge) gets wrong How can I do the accounting operations and merge fields
CodePudding user response:
You are using the DataRow
item
property to get the value for a field. This method returns an object
which you can't add. You need to cast to the proper type.
"new (T[\"ss\"] as ss, T[\"xx\"] as xx, int(T[\"ss\"]) int(T[\"xx\"]) as yy)"
CodePudding user response:
Thanks Indeed, it must be converted because it is the object
IQueryable GetSource( DataTable t, String str)
{
//Working str = "new (T[\"ss\"] as ss,T[\"xx\"] as xx )"
//Working str = "new (T[\"ss\"] as ss,T[\"xx\"] as xx , string.Concat(T[\"ss\"], T[\"xx\"]) as yy )"
//Working str = ""new (T[\"ss\"] as ss,T[\"xx\"] as xx , decimal(T[\"ss\"]) decimal(T[\"xx\"]) as yy )""
return (from T in t.AsEnumerable()
select new{T}).AsQueryable().Select(str);
}