Well, I have the following scenario:
public class Joins<TOuter, TInner, TResult>
{
public Expression<Func<TOuter, object>> outerKeySelector;
public Expression<Func<TInner, object>> innerKeySelector;
public Expression<Func<TOuter, TInner, object>> resultSelector;
public IEnumerable<TResult> r;
}
public class Test<T>
{
public IEnumerable<TResult> Join<TInner, TResult>(
Expression<Func<T, object>> outerKeySelector,
Expression<Func<TInner, object>> innerKeySelector,
Expression<Func<T, TInner, TResult>> resultSelector) where TInner : class
{
var join = new Joins<T, TInner, TResult>();
join.innerKeySelector = innerKeySelector;
join.outerKeySelector = outerKeySelector;
return join.r;
}
}
To create the join method, I relied on the link: http://msdn.microsoft.com/en-us/library/bb534644(v=vs.100).aspx
However, when I try to invoke the method, TInner is not recognized, making the method becomes invalid me returning the following error:
Cannot convert expression type 'type' to return type 'TResult'
Note: The class 'Joins' is purely a test, none of it is definitive and the var 'r' is for testing only, used only to facilitate the return.
Example of intended use:
var test = new Test<User>().Join<Permission>(u => u.Id, p => p.IdUser, (u, p) => new { Id = u.Id , Area = p.Area });
More details:
As mentioned, TInner is not recognized, so I can not make a call the correct method.
As a test I did so:
var test = new Test<User>().Join<Permission>(u => u.Id, p => p.ToString(), (u, p) => new {Id = u.Id, Name = p.ToString()});
I know p.ToString() is not correct, but is not recognizing the properties of the class indicated (in the case Permission), then put ToString() just to finish writing the method.
EDIT:
I need to use the result in a foreach/for
example:
foreach(var obj in test)
{
var id = obj.Id;
var area = obj.Area;
.
.
.
}