I can do the following:
var result = DB.Products.ToList() // .AsEnumerable() too
.Where( p => p.ID.ToString() == ViewModel.ID);
But it pulls all the products instead of only what I want, then filters locally. Without the ToList(), it fails to find/use the .ToString method in the projection. The ViewModel.ID is string from the client.
This question here talks about the same issue, minus the where clause, but the answer doesn't fix pulling every product locally.
My ViewModel.ID is string because knockout.js converts it from numeric to string if the user changes the value. I figured I would pursue this fir开发者_如何学JAVAst as it's probably easier to rule it out.
I think you are approaching the problem from the wrong direction. Convert ViewModel.ID
back to integer (int.Parse
), then you can offload the filtering back to the database. This is going to be far better than a workaround to cast p.ID
to a string at the database, a move that would likely defeat any indexing on the value at the DB.
精彩评论