<bdo id='uvs1t'></bdo><ul id='uvs1t'></ul>

    <legend id='uvs1t'><style id='uvs1t'><dir id='uvs1t'><q id='uvs1t'></q></dir></style></legend>

      <small id='uvs1t'></small><noframes id='uvs1t'>

      <i id='uvs1t'><tr id='uvs1t'><dt id='uvs1t'><q id='uvs1t'><span id='uvs1t'><b id='uvs1t'><form id='uvs1t'><ins id='uvs1t'></ins><ul id='uvs1t'></ul><sub id='uvs1t'></sub></form><legend id='uvs1t'></legend><bdo id='uvs1t'><pre id='uvs1t'><center id='uvs1t'></center></pre></bdo></b><th id='uvs1t'></th></span></q></dt></tr></i><div id='uvs1t'><tfoot id='uvs1t'></tfoot><dl id='uvs1t'><fieldset id='uvs1t'></fieldset></dl></div>

      <tfoot id='uvs1t'></tfoot>

      LINQ to Entities 无法识别方法“Int32 Parse(System.String)"方法,并

      LINQ to Entities does not recognize the method #39;Int32 Parse(System.String)#39; method, and this method cannot be translated into a store expression(LINQ to Entities 无法识别方法“Int32 Parse(System.String)方法,并且该方法无法转换为存储表

    1. <small id='rp1fn'></small><noframes id='rp1fn'>

        <legend id='rp1fn'><style id='rp1fn'><dir id='rp1fn'><q id='rp1fn'></q></dir></style></legend>

          <tbody id='rp1fn'></tbody>

      1. <i id='rp1fn'><tr id='rp1fn'><dt id='rp1fn'><q id='rp1fn'><span id='rp1fn'><b id='rp1fn'><form id='rp1fn'><ins id='rp1fn'></ins><ul id='rp1fn'></ul><sub id='rp1fn'></sub></form><legend id='rp1fn'></legend><bdo id='rp1fn'><pre id='rp1fn'><center id='rp1fn'></center></pre></bdo></b><th id='rp1fn'></th></span></q></dt></tr></i><div id='rp1fn'><tfoot id='rp1fn'></tfoot><dl id='rp1fn'><fieldset id='rp1fn'></fieldset></dl></div>
            <bdo id='rp1fn'></bdo><ul id='rp1fn'></ul>
              <tfoot id='rp1fn'></tfoot>

                本文介绍了LINQ to Entities 无法识别方法“Int32 Parse(System.String)"方法,并且该方法无法转换为存储表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用实体框架,并且我有一行代码正在获取一个 var 并将其转换回数据库的 iint.

                I am using Entity Framework, and I have a line of code that is taking a var and translating it back to an iint for the database.

                var record = context.enrollments.SingleOrDefault
                  (row => row.userId == int.Parse(UserID) && row.classId == int.Parse(ClassID));
                

                每当我尝试运行它时,我都会收到 rhis 错误.LINQ to Entities 无法识别方法 'Int32 Parse(System.String)' 方法,并且该方法无法转换为存储表达式."

                Whenever I try to run it I receive rhis error. "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."

                我也试过了

                 var record = context.enrollments.FirstOrDefault
                  (row => row.userId == Convert.ToInt32(UserID) 
                  && row.classId == Convert.ToInt32(ClassID));
                

                我收到的只是这条错误消息,LINQ to Entities 无法识别方法 'Int32 ToInt32(System.String)' 方法,并且此方法无法转换为存储表达式

                and all I receive is this error message, "LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression

                最后我也尝试了这个,我知道这很不寻常,但在过去类似的情况下它也有效.

                and finally I have tried this as well, which I know is unusual, but it has worked in the past for similar situations.

                var record = context.enrollments.SingleOrDefault
                  (row => row.userId == CommonDLL.Sanitize<int>.ConvertType(UserID) 
                  && row.classId == CommonDLL.Sanitize<int>.ConvertType(ClassID));
                

                我在其中收到此错误.如您所见,我尝试了几种不同的方法,但没有任何效果,所以任何帮助都会很棒.

                In which I get this error. As you can see I have tried seveal different things and nothing is working, so any help would be great.

                推荐答案

                Linq to Entity 中,您应该使用 query 中支持的方法code>provider 将它们转换为 expression tree 以在您的 Data Base 端运行.

                in Linq to Entity, you should use the methods in your query which is supported by your provider to convert them to expression tree to run on your Data Base side.

                默认情况下,所有提供程序都必须支持某些称为 Canonical Functions 的方法(在这里阅读更多),您也可以将用户定义函数存储过程定义为edm函数 用于 linq 查询 (在这里阅读更多)和(在这里).

                all providers must support some methods by default called Canonical Functions (Read More Here), and also you can define your user defined function and stored procedure as edm functions to use in linq query (Read More Here) and (Here).

                此外,您可以使用提供程序支持的方法,并且可以转换为 表达式树library/system.data.objects.entityfunctions%28v=vs.110%29.aspx">EntityFunctions 和 SqlFunctions.

                in addition you can use methods which is supported by providers and can be converted to expression tree which are in EntityFunctions and SqlFunctions.

                最后关于您的问题,您可以在查询之前转换 UserIDClassID,如下所示:

                and finally about your question, you can convert UserID and ClassID before your query, like this:

                var UID = int.Parse(UserID);
                var CID = int.Parse(ClassID);
                var record = context.enrollments.SingleOrDefault
                    (row => row.userId == UID && row.classId == CID);
                

                这篇关于LINQ to Entities 无法识别方法“Int32 Parse(System.String)"方法,并且该方法无法转换为存储表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                Accessing attribute info from DTE(从 DTE 访问属性信息)
                c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                C# Attributes and their uses(C# 属性及其用途)
                C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                <small id='x3Kxl'></small><noframes id='x3Kxl'>

                <i id='x3Kxl'><tr id='x3Kxl'><dt id='x3Kxl'><q id='x3Kxl'><span id='x3Kxl'><b id='x3Kxl'><form id='x3Kxl'><ins id='x3Kxl'></ins><ul id='x3Kxl'></ul><sub id='x3Kxl'></sub></form><legend id='x3Kxl'></legend><bdo id='x3Kxl'><pre id='x3Kxl'><center id='x3Kxl'></center></pre></bdo></b><th id='x3Kxl'></th></span></q></dt></tr></i><div id='x3Kxl'><tfoot id='x3Kxl'></tfoot><dl id='x3Kxl'><fieldset id='x3Kxl'></fieldset></dl></div>
                <tfoot id='x3Kxl'></tfoot>
                <legend id='x3Kxl'><style id='x3Kxl'><dir id='x3Kxl'><q id='x3Kxl'></q></dir></style></legend>
                  <tbody id='x3Kxl'></tbody>
                          <bdo id='x3Kxl'></bdo><ul id='x3Kxl'></ul>