- Using SQL Server Management
- Using MVC VS 2013 for Web
- Being in a Controller
Here materialnumb it's a LINQ query that always return only one value. Being the following...
var materialnumb = (from r in db.MaterialNumber where r.MaterialNumber == 80254842 select r.MaterialNumber);
I have another LINQ query from a SQL view that involves several other tables with inner join statements and so on (which includes the previous table db.MaterialNumber) that goes like this:
var query = (from r in db.SQLViewFinalTable where r.MaterialNumber == Convert.ToInt32(materialnumb.MaterialNumber) select r
I want to sort all the materials by the retrieved material number from the first query but it drops the following error when I try to pass the query as a model for my View:
LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression.
I assume this is because the query is an object even if its has just one value so it can't be converted into a single Int32. Even more, the query it's not being executed, it's just a query...
So, how can achieve my goal?
Additional information: I tried to convert the query outside the "final" query. It still doesn't work. Additional information: This is just an example, the true query actually has several more other querys embedded and this other querys have also other querys in them, so I need a practical way. Additional information: I have also tried to convert the query into a string and then again into an int.