User-479818971 posted
Hi ,
I want to know about is there any way to do Joining multiple list using Linq (Generic way).
I just create a generic method for joining 2 List
public static T Merge<T>(T List1, T List2) where T : new()
{
var properties = typeof(T)
.GetProperties()
.Where(p => p.CanRead && p.CanWrite && !p.GetIndexParameters().Any());
T result = new T();
foreach (var prop in properties)
{
object value = prop.GetValue(List1) ?? prop.GetValue(List2);
prop.SetValue(result, value);
}
return result;
}
List<student> _List1 = List1.Cast<student>().ToList();
List<student> _List2 = List2.Cast<student>().ToList();
var mergedlist = from a in _List1
join b in _List2
on a.stid equals b.stid
select Merge(a, b);
But i need to pass multiple List of List into Merge function .How we can achieve ?
How we can do using TModel ?