0

Here is the query

db.setupBrands.Where(x => 
    Convert.ToInt32(x.SortKey) <= id && 
    Convert.ToInt32(x.SortKey) >= desID)
.Select(x => x);

Here SortKey is string type i want to convert to int. On Convert.ToInt32() i got the following error.

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

7
  • 1
    Out of interest, if your SortKey property is always an integer, why do you have it as a string in your schema? Commented Dec 8, 2012 at 8:06
  • SortKey is String Type... @Jon Skeet Commented Dec 8, 2012 at 8:08
  • 1
    Yes, I can tell that. My point is why? If it's always got a numeric value, why don't you make it an integer in your schema? Commented Dec 8, 2012 at 8:11
  • Because i want to show it in 0001 form if i keep it int i will store it as 1. Commented Dec 8, 2012 at 8:13
  • 1
    @Zeb-ur-Rehman you can format integer value for displaying String.Format("{0:0000}", value) Commented Dec 8, 2012 at 8:14

1 Answer 1

2

EF can't translate Convert and Parse. I completely agree with the above, but, if your SortKey is nchar(4) you can try this:

string s_id = string.Format("{0:0000}", id);
string s_desID = string.Format("{0:0000}", desID );

db.setupBrands.Where(x => 
    x.SortKey <= s_id && 
    x.SortKey >= s_desID)
.Select(x => x);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.