Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有where条件的EFCore 3引发异常_C#_Ef Core 3.1 - Fatal编程技术网

C# 带有where条件的EFCore 3引发异常

C# 带有where条件的EFCore 3引发异常,c#,ef-core-3.1,C#,Ef Core 3.1,这很奇怪。我有一个这样的模型: public class UserLimit: IDbItem //IDbItem has just Id field { public virtual Guid Id { get; set; } public virtual Guid UserId { get; set; } public virtual LimitTypes LimitType { get; set; } //some enum public virtual D

这很奇怪。我有一个这样的模型:

public class UserLimit: IDbItem //IDbItem has just Id field
{
    public virtual Guid Id { get; set; }
    public virtual Guid UserId { get; set; }
    public virtual LimitTypes LimitType { get; set; } //some enum
    public virtual DateTimeOffset? ValidUntil { get; protected set; }
    int CurrentLimit { get; set; }
    int PreviousLimit { get; set; }
}
请注意,为了清晰起见,还删除了一些其他functino。 现在,我将其映射为:

public class UserLimit: IDbItem //IDbItem has just Id field
{
    public virtual Guid Id { get; set; }
    public virtual Guid UserId { get; set; }
    public virtual LimitTypes LimitType { get; set; } //some enum
    public virtual DateTimeOffset? ValidUntil { get; protected set; }
    int CurrentLimit { get; set; }
    int PreviousLimit { get; set; }
}
(b是EntityTypeBuilder)

目前,一切正常。当我在调试窗口中预览结果时,我可以看到只有一条我期望的记录。但问题在于:

UserLimit ul = result.ElementAt(0);
尽管存在对象,但我得到一个例外:

Processing of the LINQ expression 'DbSet<UserLimit>
    .Where(x => x.UserId == __userId_0 && (int)x.LimitType == (int)__limitType_1)
    .ElementAt(__p_2)' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
LINQ表达式“DbSet”的处理
其中(x=>x.UserId==\uuuuuserid\u0&(int)x.LimitType==(int)\uuuulimittype\u1)
由“NavigationExpandingExpressionVisitor”创建的.ElementAt(u p_2)”失败。这可能表明EF核心中存在缺陷或限制。看见https://go.microsoft.com/fwlink/?linkid=2101433 更多详细信息。

我的第一个想法是,它与客户端评估有关。但在客户端根本没有工作要做。只需从一个表中选择记录的简单查询。

ElementAt(0)
不是有效的LINQ可翻译函数。您应该使用
SingleOrDefault()
Single()
,在这种情况下
ElementAt(0)
不是有效的LINQ可翻译函数。在这种情况下,您可能应该使用
SingleOrDefault()
Single()
。谢谢。就是这样。从你的评论中做出回答,这样我就可以给你打分:)
Processing of the LINQ expression 'DbSet<UserLimit>
    .Where(x => x.UserId == __userId_0 && (int)x.LimitType == (int)__limitType_1)
    .ElementAt(__p_2)' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.