English 中文(简体)
Linq。 Dyanmic GroupJoin implementation
原标题:Linq.Dyanmic GroupJoin implementation

我正致力于在班克建立推广方法。 共同市场动态项目。 但出于某种原因,它不会运行。 签名似乎相符。

public static IQueryable GroupJoin(this IQueryable outer, IEnumerable inner, string outerSelector, string innerSelector, string resultsSelector, params object[] values)
{
    if (inner == null) throw new ArgumentNullException("inner");
    if (outerSelector == null) throw new ArgumentNullException("outerSelector");
    if (innerSelector == null) throw new ArgumentNullException("innerSelector");
    if (resultsSelector == null) throw new ArgumentNullException("resultsSelctor");

    LambdaExpression outerSelectorLambda = DynamicExpression.ParseLambda(outer.ElementType, null, outerSelector, values);
    Type enumType = GetList(inner.AsQueryable().ElementType).GetType();

    LambdaExpression innerSelectorLambda = DynamicExpression.ParseLambda(inner.AsQueryable().ElementType, null, innerSelector, values);

    ParameterExpression[] parameters = new ParameterExpression[] { 
    Expression.Parameter(outer.ElementType, "outer"), Expression.Parameter(enumType, "inner") };
    LambdaExpression resultsSelectorLambda = DynamicExpression.ParseLambda(parameters, null, resultsSelector, values);        

    return outer.Provider.CreateQuery(
        Expression.Call(
            typeof(Queryable), "GroupJoin",
            new Type[] { outer.ElementType, inner.AsQueryable().ElementType, outerSelectorLambda.Body.Type, resultsSelectorLambda.Body.Type },
            outer.Expression, inner.AsQueryable().Expression, Expression.Quote(outerSelectorLambda), Expression.Quote(innerSelectorLambda), Expression.Quote(resultsSelectorLambda)));
}

public static IEnumerable GetList(System.Type type)
{
    return (IEnumerable)Activator.CreateInstance(typeof(List<>).MakeGenericType(type));
}

该法典给我留下以下错误:

没有关于类型系统的通用方法组。 Linq。 证据符合所提供的类型论点和论点。 如果该方法是非遗传性的,则不应提供任何类型的论据。

In looking at the results of each piece they seem to match: Writing the follwing GroupJoin:

man.Contacts.GroupJoin(man.ContactAddresses, param_0 => param_0.ContactId, param_0 => param_0.ContactId, 
                (outer, inner) => new { ContactId = outer.ContactId, FirstName = outer.FirstName, LastName = outer.LastName, MI = outer.MiddleInitial, ContactAddresses = inner });

我收到了以下的ug:

.Call System.Linq.Queryable.GroupJoin(
.Constant<IdeaBlade.EntityModel.EntityQueryProxy`1[LOC.AMP.Data.DomainModel.Contact]>(IdeaBlade.EntityModel.EntityQueryProxy`1[LOC.AMP.Data.DomainModel.Contact]),    .Constant<IdeaBlade.EntityModel.EntityQueryProxy`1[LOC.AMP.Data.DomainModel.ContactAddress]>(IdeaBlade.EntityModel.EntityQueryProxy`1[LOC.AMP.Data.DomainModel.ContactAddress]),
 (.Lambda #Lambda1<System.Func`2[LOC.AMP.Data.DomainModel.Contact,System.Int64]>),
 (.Lambda #Lambda2<System.Func`2[LOC.AMP.Data.DomainModel.ContactAddress,System.Int64]>),
 (.Lambda #Lambda3<System.Func`3[LOC.AMP.Data.DomainModel.Contact,System.Collections.Generic.IEnumerable`1[LOC.AMP.Data.DomainModel.ContactAddress],    <>f__AnonymousType0`5[System.Int64,System.String,System.String,System.String,System.Collections.Generic.IEnumerable`1[LOC.AMP.Data.DomainModel.ContactAddress]]]>))
.Lambda #Lambda1<System.Func`2[LOC.AMP.Data.DomainModel.Contact,System.Int64]>(LOC.AMP.Data.DomainModel.Contact $param_0)
{
    $param_0.ContactId
}    
.Lambda #Lambda2<System.Func`2[LOC.AMP.Data.DomainModel.ContactAddress,System.Int64]>(LOC.AMP.Data.DomainModel.ContactAddress $param_0)
{
    $param_0.ContactId
}    
.Lambda 
    #Lambda3<System.Func`3
    [
        LOC.AMP.Data.DomainModel.Contact, System.Collections.Generic.IEnumerable`1[LOC.AMP.Data.DomainModel.ContactAddress],
        <>f__AnonymousType0`5
        [
            System.Int64,System.String,System.String,System.String, System.Collections.Generic.IEnumerable`1
            [
                LOC.AMP.Data.DomainModel.ContactAddress
            ]
        ]
    ]>
    (LOC.AMP.Data.DomainModel.Contact $outer, System.Collections.Generic.IEnumerable`1
        [LOC.AMP.Data.DomainModel.ContactAddress] $inner) 

    {
    .New <>f__AnonymousType0`5[System.Int64,System.String,System.String,System.String,System.Collections.Generic.IEnumerable`1[LOC.AMP.Data.DomainModel.ContactAddress]](
        $outer.ContactId,
        $outer.FirstName,
        $outer.LastName,
        $outer.MiddleInitial,
        $inner)
}

The following GroupJoin:

man.Contacts.GroupJoin(man.ContactAddresses, "ContactId", "ContactId", "new (outer.ContactId as ContactId, outer.FirstName as FirstName, outer.LastName as LastName, outer.MiddleInitial as MI, inner as ContactAddresses)");

然后看一下 de:

.Call GroupJoin (
{value(IdeaBlade.EntityModel.EntityQueryProxy 1[LOC.AMP.Data.DomainModel.Contact])},    {value(IdeaBlade.EntityModel.EntityQueryProxy 1[LOC.AMP.Data.DomainModel.ContactAddress])},
 (.Lambda #Lambda1<System.Func 2[LOC.AMP.Data.DomainModel.Contact,System.Int64]>),
 (.Lambda #Lambda1<System.Func 2[LOC.AMP.Data.DomainModel.ContactAddress,System.Int64]>),
 (.Lambda #Lambda1<System.Func 3[LOC.AMP.Data.DomainModel.Contact,System.Collections.Generic.List`1[LOC.AMP.Data.DomainModel.ContactAddress],DynamicClass1]>)

//ContactId
.Lambda #Lambda1<System.Func 2[LOC.AMP.Data.DomainModel.Contact,System.Int64]>(LOC.AMP.Data.DomainModel.Contact $var1) 
{
    $var1.ContactId
}

//CA.ContactId
.Lambda #Lambda1<System.Func 2[LOC.AMP.Data.DomainModel.ContactAddress,System.Int64]>(LOC.AMP.Data.DomainModel.ContactAddress $var1)
{
    $var1.ContactId
}
//Dynamic Result
.Lambda #Lambda1<System.Func`3[LOC.AMP.Data.DomainModel.Contact,System.Collections.Generic.List`1[LOC.AMP.Data.DomainModel.ContactAddress],DynamicClass1]>(
    LOC.AMP.Data.DomainModel.Contact $outer,
    System.Collections.Generic.List`1[LOC.AMP.Data.DomainModel.ContactAddress] $inner)
    {
    .New DynamicClass1(){
        ContactId = $outer.ContactId,
        FirstName = $outer.FirstName,
        LastName = $outer.LastName,
        MI = $outer.MiddleInitial,
        ContactAddresses = $inner
    }
}

The only thing different is List<T> compared to IEnumerable. But List<T> is IEnumerable. The error reads like the signature is wrong. I just can t figure it out.

任何煽动都将是巨大的。

问题回答

本声明:

man.Contacts.GroupJoin

<代码>Contacts的类型如何? 是否继承<条码>。 IQueryable? 或IQueryable<T>?

我的猜测是<条码>。 IQueryable<T>。 这一错误:

No generic method GroupJoin on type System.Linq.Queryable is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

说的是,在这种方法中提供了一些类型的论据,它无法找到一种与这些类型的论点相一致的通用方法。 你写的Join集团期望no。 因此,你可能不得不修改这些论点,以期望某个或几个方面。

我认为,这个问题还有可能涉及第二个参数,即通过<代码>man.Contact Addresses。 但<代码>Contacts是第一个看一看点。

我知道这可能太晚,但我认为这是答案:

使用:

Type enumType = typeof(IEnumerable<>).MakeGenericType(inner.AsQueryable().ElementType);

它为我工作。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签