1

Here is how I can return result of merging two string columns:

    context.DBSET.Select(e => e.STRING_PROPERTY + e.STRING_PROPERTY)...

How can I merge e.STRING_PROPERTY + e.INTEGER_PROPERTY in one string result ?

user2265414
  • 111
  • 1
  • 1
  • 6

2 Answers2

1

You have to convert it to a string using SqlFunctions.StringConvert:

var results = context.DBSET
                     .Select(e => e.STRING_PROPERTY + SqlFunctions.StringConvert((double)e.INTEGER_PROPERTY));
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
0

Several C# members are supported by Linq to Entities and Linq to Sql behind the scenes. Amoung these, are String.ToString() and DateTime.Now. You could write:

    context.DBSET.Select(e => e.STRING_PROPERTY + e.INTEGER_PROPERY.ToString())...

As @Reed pointed out, the SqlFunctions will also work, and will provide a more general, but less readable set of operations that can be performed in your query.

Doug
  • 2,441
  • 2
  • 19
  • 22
  • 1
    You will get this eror: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression. )) – user2265414 Apr 12 '13 at 17:28