“在此上下文中仅支持原始类型”

发布于 2024-11-09 03:05:31 字数 704 浏览 0 评论 0原文

我在代码的最后一行遇到了这个异常:

无法创建“System.Linq.EnumerableQuery`1”类型的常量值。此上下文仅支持原始类型(“例如 Int32、String 和 Guid”)。

我的代码:

using (GharardadhaEntities dal = new GharardadhaEntities())
{
    IQueryable<TBL_Gharardad> Gharardadha =
        from record in dal.TBL_Gharardad
        join shenase in Query on record.PK_Shenase equals shenase
        select record;

    var q = (from record in dal.TBL_MabalegheDariaftieMahane
             where record.TBL_Gharardad == Gharardadha.First()
             select record); 

    ulong v = (ulong)Gharardadha.First().MablagheDariaftiKol;// I have got the error on this statement
}

我的代码有什么问题?

I have got this exception in the last line of my code:

Unable to create a constant value of type 'System.Linq.EnumerableQuery`1'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

My Code:

using (GharardadhaEntities dal = new GharardadhaEntities())
{
    IQueryable<TBL_Gharardad> Gharardadha =
        from record in dal.TBL_Gharardad
        join shenase in Query on record.PK_Shenase equals shenase
        select record;

    var q = (from record in dal.TBL_MabalegheDariaftieMahane
             where record.TBL_Gharardad == Gharardadha.First()
             select record); 

    ulong v = (ulong)Gharardadha.First().MablagheDariaftiKol;// I have got the error on this statement
}

What is wrong with my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上芳菲 2024-11-16 03:05:31

我认为问题出在查询。该异常表明您无法将 EnumerableQuery 传递给 Linq-to-entities。如果 QueryIEnumerable 尝试将第一个查询重写为:

IQueryable<TBL_Gharardad> Gharardadha =
    from record in dal.TBL_Gharardad
    where Query.Contains(record.PK_Shenase)
    select record;

I believe that the problem is Query. The exception says that you cannot pass EnumerableQuery to Linq-to-entities. If Query is IEnumerable try to rewrite first query as:

IQueryable<TBL_Gharardad> Gharardadha =
    from record in dal.TBL_Gharardad
    where Query.Contains(record.PK_Shenase)
    select record;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文