int to Entity Framework中的字符串 [英] int to string in Entity Framework

查看:80
本文介绍了int to Entity Framework中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将一个int转换为一个字符串链接到EF?

How do you convert an int to a string in Link to EF?

不能想象将一个int转换为一个字符串,而实体框架不能弄清楚什么SQL代码段将 .ToString()转换成。

The clr cant imagine casting an int to a string and Entity framework cant figure out what SQL snippet to translate .ToString() into.

那么如何编写返回一个字符串的linq语句呢的一个int?

So how do you write a linq statement that returns a string instead of an int?

推荐答案

可惜,EF不知道如何转换 .ToString()。您必须使用嵌入式功能SqlFunctions.StringConvert: http://msdn.microsoft。 com / en-us / library / dd466292.aspx
也没有int的重载,所以你必须将typecast重新加载: - (

Sadly EF does not know how to convert .ToString(). You must use the embedded function SqlFunctions.StringConvert: http://msdn.microsoft.com/en-us/library/dd466292.aspx Also there is no overload for int so you must typecast to double :-(

var vendors = 
   from v in Vendors  
   select new
   {             
       Code = SqlFunctions.StringConvert((double)v.VendorId)
   }; 

这篇关于int to Entity Framework中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆