c# - 在 linq to entities 中将 int 转换为字符串

标签 c# .net linq-to-entities tostring

我的代码是:

        var currency = (from ac in db.shop
          join cur in db.books
          on ac.CODE equals cur.CODE.ToString()  //here is the Error
          // because "ac.code is type strig" & "cur.code is type long 
          where ac.ID == merchantId
          select new Currency()
          {
                 ShopCode = ac.CODE,
                 PosCode = ac.POSCODE,
           }).ToList();

我发现 .ToString()、SqlFunctions.StringConvert(long) 在连接查询条件下不起作用,但在查询的“选择”区域起作用。 但是 Devart.Data.Oracle.Entity.OracleFunctions.ToChar((long)cur.CODE) 工作正常。由于我使用的是 Entity Framework ,因此特定数据库类型(即 oracle 或 sql server)不应该有问题。即使我将来从 oracle 更改为 sql,它也应该可以工作。

请给我一个解决方案。

最佳答案

你试过转换这个吗?

尝试:ac.CODE 等于(字符串)cur.CODE

关于c# - 在 linq to entities 中将 int 转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8091082/

相关文章:

c# - 来自 .Net 的异步电子邮件

c# - .NET 4.5.2 代码会在 <4.5.2 机器上抛出异常吗?

c# - 在 C# 中使用十六进制文字将整数设置为负值

c# - FileVersionInfo.GetVersionInfo 显示替换文件的错误版本

c# - 图像格式转换异常缓慢

c# - JsonValue 和 JsonObject 有什么区别?

c# - Expand 在查询中做了什么?

c# - MVC中如何使用多个路由

assemblies - 不同程序集中的实体容器和模型生成

entity-framework - 将 ESQL 转换为 LINQ 到实体。按相关实体排序