1
votes

when I trying to run following code.

var result = from c in db.brand
             where c.title.contains("test")
             select c.title + "-" +c.brand;

List<string> lst = r.ToList();

it gives following error.

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

3

3 Answers

6
votes

I would suggest fetching the title and the brand in an anonymous type, and then performing the string concatenation in-process:

var list = db.Brand.Where(c => c.Title.Contains("test"))
                   .Select(c => new { c.Title, c.Brand })
                   .AsEnumerable() // Rest of the query in-process
                   .Select(x => x.Title + " " + x.Brand)
                   .ToList();
1
votes

try this:

var result = from c in db.brand where c.title.contains("test") select c;
var finalResult = result.ToList().Select(ss=> ss.title + "-" + ss.brand);
-1
votes

try:

var result = from c in db.brand where c.title.contains("test") select new { c.title + "-" +c.brand }