Here's how to get data using c# and Linq
Here's how to get data using c# and Linq
After pulling out what little hair I have left, I turned to MS Support and the always fantastic, Lingzhi Sun, came up with this...
[code]
public static List ToStringArray(this IQueryable source)
{
Type type = source.ElementType;
var properties = type.GetProperties();
List strs;
List list = new List();
foreach (var i in source)
{
strs = new List();
foreach (var p in properties)
{
object value = p.GetValue(i, null);
strs.Add(value == null ? null : value.ToString());
}
list.Add(strs.ToArray());
}
return list;
}
[/code]
which simplifies the call to your query as this
[code]
var list = db.Table1.Select("new(ID, Name)").ToStringArray();
[/code]
or event easier
[code]
aaData = db.Table1.Select("new(ID, Name)").ToStringArray();
[/code]
I hope this saves others the time I spent,
Patrick
[code]
public static List ToStringArray(this IQueryable source)
{
Type type = source.ElementType;
var properties = type.GetProperties();
List strs;
List list = new List();
foreach (var i in source)
{
strs = new List();
foreach (var p in properties)
{
object value = p.GetValue(i, null);
strs.Add(value == null ? null : value.ToString());
}
list.Add(strs.ToArray());
}
return list;
}
[/code]
which simplifies the call to your query as this
[code]
var list = db.Table1.Select("new(ID, Name)").ToStringArray();
[/code]
or event easier
[code]
aaData = db.Table1.Select("new(ID, Name)").ToStringArray();
[/code]
I hope this saves others the time I spent,
Patrick
This discussion has been closed.
Replies
Regards,
Allan
Have a great weekend!