4

I have to convert data type from long to string in linq query join statement. e.g.

 from t1 in table1

 join t2 in table2 on new {t1.field1, t1.field2} equals new {t2.field1, t2.field2} 

 select new {t1.field1,t2.field1 all columns}

t1.field2 is of long type and t2.field2 is of string type. When I put ToString method it throws exception. Exception message

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

Any help will be appreciated.

1 Answer 1

4

Use SqlFunctions.StringConvert

SqlFunctions.StringConvert((double) t1.field2)
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks habib it is working fine but it is not returning the result while the SQL query is giving result on the same filter
@user1748975, you should check the generated SQL query against your LINQ expression and see what is going on
(((STR( CAST( [t1].[field2] AS float))) = [t2].[field2]) OR ((STR( CAST( [t1].[field2] AS float)) IS NULL) AND ([t2].[field2] IS NULL))) it is adding this filter there. When I put the same filter in the SQL query it also doesn't give results
@user1748975, try StringConvert on the other field in your LINQ query

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.