C# Linq错误:不是组键的成员(当GroupBy由许多非键列组成时)
我需要按许多不属于表索引的列进行分组。表的键是属性“id” 我已经阅读并基本了解了关于扩展、属性等的各种方法,但是这种方法是我唯一可以使用的方法C# Linq错误:不是组键的成员(当GroupBy由许多非键列组成时),c#,sql,linq,sql-server-express,telerik-open-access,C#,Sql,Linq,Sql Server Express,Telerik Open Access,我需要按许多不属于表索引的列进行分组。表的键是属性“id” 我已经阅读并基本了解了关于扩展、属性等的各种方法,但是这种方法是我唯一可以使用的方法 var query = from f in this.dbContext.Tokens group f by new { f.PI, f.TI, f.UIDP, f.AttributesJSON, f.IssuerParameters, f.IsDeviceProtected , f.FriendlyName}
var query = from f in this.dbContext.Tokens
group f by new { f.PI, f.TI, f.UIDP, f.AttributesJSON, f.IssuerParameters, f.IsDeviceProtected , f.FriendlyName}
into myGroup
where myGroup.Count() > 0
select new
{
myGroup.Key.UIDP,
myGroup.Key.TI,
myGroup.Key.PI,
myGroup.Key.AttributesJSON,
myGroup.Key.IssuerParameters,
myGroup.Key.FriendlyName,
Count = myGroup.Count(),
Subgroups = from privateTokens in myGroup
select new
{
// AttributesJSON = privateTokens.AttributesJSON,
// FriendlyName = privateTokens.FriendlyName,
Id = privateTokens.Id,
// IsDeviceProtected = privateTokens.IsDeviceProtected,
// IssuerParameters = privateTokens.IssuerParameters,
// PI = privateTokens.PI,
// PrivateKey = privateTokens.PrivateKey,
// TI = privateTokens.TI,
TokenData = privateTokens.TokenData,
UIDP = privateTokens.UIDP,
}
};
我使用的ORM是Telerik Openaccess,但是我认为这是一个SQL问题
错误如下
Not a member of the group key.
Parameter name: memberInfo
Actual value was Int32 Id.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Not a member of the group key.
Parameter name: memberInfo
Actual value was Int32 Id.
Source Error:
Line 86: };
Line 87:
Line 88: string asdfdsfd = query.ToString();
Line 89:
Line 90: // todo, limit to a per user
Source File: \\psf\home\Documents\Visual Studio 2013\Projects\BitClearTokens\BitclearClient\Controllers\TokenController.cs Line: 88
Stack Trace:
[ArgumentOutOfRangeException: Not a member of the group key.
Parameter name: memberInfo
Actual value was Int32 Id.]
Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(Type resultType, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) +2571
Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) +97
[InvalidOperationException: An exception occured during the execution of 'Extent<BitclearProverModel.Tokens>().GroupBy(f => new <>f__AnonymousType3`7(PI = f.PI, TI = f.TI, UIDP = f.UIDP, AttributesJSON = f.AttributesJSON, IssuerParameters = f.IssuerParameters, IsDeviceProtected = f.IsDeviceProtected, FriendlyName = f.FriendlyName)).Where(myGroup => (myGroup.Count() > 0)).Select(myGroup => new <>f__AnonymousType5`8(UIDP = myGroup.Key.UIDP, TI = myGroup.Key.TI, PI = myGroup.Key.PI, AttributesJSON = myGroup.Key.AttributesJSON, IssuerParameters = myGroup.Key.IssuerParameters, FriendlyName = myGroup.Key.FriendlyName, Count = myGroup.Count(), Subgroups = myGroup.Select(privateTokens => new <>f__AnonymousType4`3(Id = privateTokens.Id, TokenData = privateTokens.TokenData, UIDP = privateTokens.UIDP))))'. Failure: Not a member of the group key.
Parameter name: memberInfo
Actual value was Int32 Id.
See InnerException for more details.
Complete Expression:
.Call System.Linq.Queryable.Select(
.Call System.Linq.Queryable.Where(
.Call System.Linq.Queryable.GroupBy(
.Constant<Telerik.OpenAccess.Query.ExtentQueryImpl`1[BitclearProverModel.Tokens]>(Extent<BitclearProverModel.Tokens>()),
'(.Lambda #Lambda1<System.Func`2[BitclearProverModel.Tokens,<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String]]>))
,
'(.Lambda #Lambda2<System.Func`2[System.Linq.IGrouping`2[<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens],System.Boolean]>))
,
'(.Lambda #Lambda3<System.Func`2[System.Linq.IGrouping`2[<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens],<>f__AnonymousType5`8[System.String,System.String,System.String,System.String,System.String,System.String,System.Int32,System.Collections.Generic.IEnumerable`1[<>f__AnonymousType4`3[System.Int32,System.String,System.String]]]]>))
.Lambda #Lambda1<System.Func`2[BitclearProverModel.Tokens,<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String]]>(BitclearProverModel.Tokens $f)
{
.New <>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String](
$f.PI,
$f.TI,
$f.UIDP,
$f.AttributesJSON,
$f.IssuerParameters,
$f.IsDeviceProtected,
$f.FriendlyName)
}
.Lambda #Lambda2<System.Func`2[System.Linq.IGrouping`2[<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens],System.Boolean]>(System.Linq.IGrouping`2[<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens] $myGroup)
{
.Call System.Linq.Enumerable.Count($myGroup) > 0
}
.Lambda #Lambda3<System.Func`2[System.Linq.IGrouping`2[<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens],<>f__AnonymousType5`8[System.String,System.String,System.String,System.String,System.String,System.String,System.Int32,System.Collections.Generic.IEnumerable`1[<>f__AnonymousType4`3[System.Int32,System.String,System.String]]]]>(System.Linq.IGrouping`2[<>f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens] $myGroup)
{
.New <>f__AnonymousType5`8[System.String,System.String,System.String,System.String,System.String,System.String,System.Int32,System.Collections.Generic.IEnumerable`1[<>f__AnonymousType4`3[System.Int32,System.String,System.String]]](
($myGroup.Key).UIDP,
($myGroup.Key).TI,
($myGroup.Key).PI,
($myGroup.Key).AttributesJSON,
($myGroup.Key).IssuerParameters,
($myGroup.Key).FriendlyName,
.Call System.Linq.Enumerable.Count($myGroup),
.Call System.Linq.Enumerable.Select(
$myGroup,
.Lambda #Lambda4<System.Func`2[BitclearProverModel.Tokens,<>f__AnonymousType4`3[System.Int32,System.String,System.String]]>)
)
}
.Lambda #Lambda4<System.Func`2[BitclearProverModel.Tokens,<>f__AnonymousType4`3[System.Int32,System.String,System.String]]>(BitclearProverModel.Tokens $privateTokens)
{
.New <>f__AnonymousType4`3[System.Int32,System.String,System.String](
$privateTokens.Id,
$privateTokens.TokenData,
$privateTokens.UIDP)
}
]
Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(Type type, Int32 elementAt, Object[] groupResolutionParamValues, Boolean single, Boolean checkOid) +531
Telerik.OpenAccess.Query.ExpressionCompiler.GetBackendQuery(Type resultType) +125
Telerik.OpenAccess.Query.ExpressionExecution.PerformQueryCompilation(Expression expr, ChainedContext ctx, Boolean tryGetObjectById, Type resultType, String dump, QueryOptions options) +230
Telerik.OpenAccess.Query.Piece`1.ToString() +415
BitclearClient.Controllers.<Index>d__0.MoveNext() in \\psf\home\Documents\Visual Studio 2013\Projects\BitClearTokens\BitclearClient\Controllers\TokenController.cs:88
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
lambda_method(Closure , Task ) +64
System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +31
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +67
System.Web.Mvc.Async.<>c__DisplayClass3f.<BeginInvokeAsynchronousActionMethod>b__3e(IAsyncResult asyncResult) +16
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9688704
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
不是组密钥的成员。
参数名称:memberInfo
实际值为Int32 Id。
描述:在执行当前web请求期间发生未经处理的异常。请查看堆栈跟踪,以了解有关错误及其在代码中起源的详细信息。
异常详细信息:System.ArgumentOutOfRangeException:不是组键的成员。
参数名称:memberInfo
实际值为Int32 Id。
源错误:
第86行:};
第87行:
第88行:字符串asdfdsfd=query.ToString();
第89行:
第90行://todo,限制为每个用户一个
源文件:\\psf\home\Documents\Visual Studio 2013\Projects\BitClearTokens\BitclearClient\Controllers\TokenController.cs行:88
堆栈跟踪:
[ArgumentOutOfRangeException:不是组密钥的成员。
参数名称:memberInfo
实际值为Int32 Id.]
Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQueryImpl(类型resultType,Int32 elementAt,对象[]groupResolutionParamValues,布尔单值,布尔checkOid)+2571
Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(类型类型,Int32 elementAt,对象[]groupResolutionParamValues,布尔单,布尔校验)+97
[InvalidOperationException:在执行'Extent().GroupBy(f=>new f_uuAnonymousType3`7(PI=f.PI,TI=f.TI,UIDP=f.UIDP,AttributesJSON=f.AttributesJSON,IssuerParameters=f.IssuerParameters,IsDeviceProtected=f.IsDeviceProtected,FriendlyName=f.FriendlyName))期间发生异常。其中(myGroup=>(myGroup.Count()>0)).Select(myGroup=>new f_uAnonymousType5`8(UIDP=myGroup.Key.UIDP,TI=myGroup.Key.TI,PI=myGroup.Key.PI,AttributesJSON=myGroup.Key.AttributesJSON,IssuerParameters=myGroup.Key.IssuerParameters,FriendlyName=myGroup.Key.FriendlyName,Count=myGroup.Count(),Subgroups=myGroup.Select(PrivateTokes=>new f_uAnonymousType4`3(Id=privateTokens.Id,TokenData=privateTokens.TokenData,UIDP=privateTokens.UIDP)))”。失败:不是组密钥的成员。
参数名称:memberInfo
实际值为Int32 Id。
有关更多详细信息,请参见InnerException。
完整表达:
.Call System.Linq.Queryable.Select(
.Call System.Linq.Queryable.Where(
.Call System.Linq.Queryable.GroupBy(
.常数(范围()),
“(.Lambda#Lambda1))
,
“(.Lambda#Lambda2))
,
“(.Lambda#Lambda3))
.Lambda#Lambda1(BitclearProverModel.Tokens$f)
{
.New f__AnonymousType3`7[System.String,System.String,System.String,System.String,System.String,System.String,System.Boolean,System.String](
$f.PI,
$f.TI,
$f.UIDP,
$f.AttributesJSON,
$f.发行人参数,
$f.IsDeviceProtected,
$f.FriendlyName)
}
.Lambda#Lambda2(System.Linq.i分组`2[f#u匿名类型3`7[System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens]$myGroup)
{
.Call System.Linq.Enumerable.Count($myGroup)>0
}
.Lambda#Lambda3(System.Linq.i分组`2[f#u匿名类型3`7[System.String,System.String,System.String,System.String,System.Boolean,System.String],BitclearProverModel.Tokens]$myGroup)
{
.New f__AnonymousType5`8[System.String,System.String,System.String,System.String,System.String,System.Int32,System.Collections.Generic.IEnumerable`1[f__AnonymousType4`3[System.Int32,System.String,System.String]](
($myGroup.Key).UIDP,
($myGroup.Key).TI,
($myGroup.Key).PI,
($myGroup.Key).AttributesJSON,
($myGroup.Key)。发行人参数,
($myGroup.Key).FriendlyName,
.Call System.Linq.Enumerable.Count($myGroup),
.Call System.Linq.Enumerable.Select(
$myGroup,
.Lambda#Lambda4)
)
}
.Lambda#Lambda4(BitclearProverModel.Tokens$privateTokens)
{
.New f__AnonymousType4`3[System.Int32,System.String,System.String](
$privateTokens.Id,
$privateTokens.TokenData,
$privateTokens.UIDP)
}
]
Telerik.OpenAccess.Query.ExpressionCompiler.PerformDatabaseQuery(类型类型,Int32 elementAt,对象[]groupResolutionParamValues,布尔单,布尔校验)+531
Telerik.OpenAccess.Query.ExpressionCompiler.GetBackendQuery(类型resultType)+125
Telerik.OpenAccess.Query.ExpressionExecution.PerformQueryCompilation(表达式表达式表达式、链接上下文ctx、布尔tryGetObjectById、类型resultType、字符串转储、查询选项)+230
Telerik.OpenAccess.Query.Piece`1.ToString()+415
\\psf\home\Documents\Visual Studio 2013\Projects\BitClearTokens\BitclearClient\Controllers\TokenController.cs:88中的BitclearClient.Controllers.d\uu 0.MoveNext()
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter.GetResult()+21
lambda_方法(闭包,任务)+64
System.Threading.Tasks.TaskHelperExtensions.ThrowIfFaulted(任务任务)+31
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)+67
System.Web.Mvc.Async.c__显示类3f.b__3e(IAsyncResult asyncResult)+16
System.Web.Mvc.Async.WrappedAsyncResult`1.End()+57
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+48
System.Web.Mvc.Async.c__显示类39.b__33()+57
System.Web.Mvc.Async.c__DisplayClass4f.b__49()+223
System.Web.Mvc.Async.c\u Disp
// this is the removed line
Subgroups = from privateTokens in myGroup
select new
{
// AttributesJSON = privateTokens.AttributesJSON,
// FriendlyName = privateTokens.FriendlyName,
Id = privateTokens.Id,
// IsDeviceProtected = privateTokens.IsDeviceProtected,
// IssuerParameters = privateTokens.IssuerParameters,
// PI = privateTokens.PI,
// PrivateKey = privateTokens.PrivateKey,
// TI = privateTokens.TI,
TokenData = privateTokens.TokenData,
UIDP = privateTokens.UIDP,
}
var query = from f in this.dbContext.Tokens
group f by new { f.PI, f.TI, f.UIDP, f.AttributesJSON, f.IssuerParameters, f.IsDeviceProtected , f.FriendlyName}
into myGroup
where myGroup.Count() > 0
select new
{
myGroup.Key.UIDP,
myGroup.Key.TI,
myGroup.Key.PI,
myGroup.Key.AttributesJSON,
myGroup.Key.IssuerParameters,
myGroup.Key.FriendlyName,
Count = myGroup.Count(),
Subgroups = myGroup
};
var groupedResult = query.ToList();
var resultWithSubGroups = from gr in groupedResult
select new
{
gr.UIDP,
gr.TI,
gr.PI,
gr.AttributesJSON,
gr.IssuerParameters,
gr.FriendlyName,
gr.Count,
Subgroups = from privateTokens in gr
select new
{
// AttributesJSON = privateTokens.AttributesJSON,
// FriendlyName = privateTokens.FriendlyName,
Id = privateTokens.Id,
// IsDeviceProtected = privateTokens.IsDeviceProtected,
// IssuerParameters = privateTokens.IssuerParameters,
// PI = privateTokens.PI,
// PrivateKey = privateTokens.PrivateKey,
// TI = privateTokens.TI,
TokenData = privateTokens.TokenData,
UIDP = privateTokens.UIDP,
}
};