When I convert, I get LINQ to Entities Int32 ToInt32(System.String).

entity-framework linq-to-sql

Question

I get LINQ to Entities Int32 ToInt32(System.String) when convert.i tried int.Parse() , SqlFunction and EdmFunction but the problem still going on.

Exception:

System.NotSupportedException: LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression

Code:

try
    {
        ModelEntities me = new ModelEntities();
        var query = from p in me.Products
                    join c in me.ProductCategories
                    on Convert.ToInt32(p.CategoryId) equals c.CategoryId
                    select new
                    {
                        p.ProductTitle,
                        c.CategoryName
                    };
        rptProducts.DataSource = query;
        rptProducts.DataBind();
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
1
2
5/24/2012 1:41:00 PM

Popular Answer

You cannot use Convert.ToInt32 inside your linq query. Linq has its own syntax and does not recognize external methods.

Either you have to extract the variable you are looking for to C#, convert it, and use it as a variable in another query. Or you could make both categoryIDs ints, if you have access to the database. It makes sense that similar fields like those should be of the same type.

Hope that helps!

9
5/24/2012 1:48:42 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow