LINQ to Entities 不识别方法“System int string 转换的问题
这个问题困扰了挺久,网上找了挺多方法 都太好使。
分几种情况。
1.如果查询结果 转换,那比较容易。
var q = from c in db.Customers
where c.Country == "UK" || c.Country == "USA"
select new
{
Phone = c.Phone,
InternationalPhone =
PhoneNumberConverter(c.Country, c.Phone)
};
public string PhoneNumberConverter(stringCountry, string Phone){此处省略}
可以自定义 转换格式 随意怎么写。
2.如果是查询条件中转换,比如 A表的 id (int型) 与B 表的 id(varchar) 进行匹配的时候
需要用到SqlFunctions.StringConvert((decimal)a.id, 10, 0) == b.id
网上最终的解决方法就是这个。 但是如果 B表的id 是 “ 1”,那就没办法匹配了
我最终的解决办法是 这样的。
var a = (from a in _db.a select a).tolist();
var b = (from a in _db.a select a).tolist();
var c = (from aa in a
from bb in b
where a.id.tostring() == b.id select new{a.id}).tolist();
先查询出来 A,B的数据 用 linq to list 进行匹配,不在 linq to entity 中进行。因为 linq to entity 中不支持很多函数 .tostring , int.parse() 不支持
所以转到 list 重新匹配 查询一次。 算是个 解决问题的笨方法。
LINQ to Entities 不识别方法“System int string 转换的问题的更多相关文章
- Linq中字段数据类型转换问题(Linq to entity,LINQ to Entities 不识别方法"System.String ToString()"问题解决)
1.在工作中碰到这样一个问题: 使用linq时,需要查询两个表,在这两张表中关联字段分别是int,和varchar()也就是string,在linq中对这两个字段进行关联, 如果强制类型转换两个不同类 ...
- LINQ to Entities 不识别方法“System.DateTime AddDays(Double)
今天本想在linq里按照时间筛选一下超时的数据,一共两个字段FeedBackTime(计划反馈时间).EndTime(实际反馈时间).需求是这样的,查找数据库里所有EndTime大于FeedBackT ...
- LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式 的解决方法
一.案例1,及解决方案: "LINQ to Entities 不识别方法"System.String ToString()",因此该方法无法转换为存储表达式." ...
- LINQ to Entities 不识别方法“System.String ToString(System.String)”,因此该方法无法转换为存储表达式。
来源:https://www.cnblogs.com/hao-1234-1234/p/9112434.html 6 Select的时候,时间无法转换成 年月日 YYMMMdd 报错:LINQ to ...
- LINQ to Entities 不识别方法“System.String ToString()”,因此该方法无法转换为存储表达式。
var data = DataSource.Skip(iDisplayStart).Take(iDisplayLength).Select(o => new { MatNR = o.MatNR, ...
- LINQ to Entities 不识别方法“System.String get_Item(Int32)”,因此该方法无法转换为存储表达式。
1.LINQ to Entities 不识别方法“System.String get_Item(Int32)”,因此该方法无法转换为存储表达式.项目中发现linq to entities 不识别? , ...
- LINQ to Entities 不识别方法“System.Guid Parse(System.String)”,因此该方法无法转换为存储表达式。
LINQ to Entities 不识别方法"System.Guid Parse(System.String)",因此该方法无法转换为存储表达式. linq 中不能转换类型
- LinQ to entities 不能识别方法“system.string.ToString(system.String)”.因此该方法无法转换为存储表达式
[我也是刚研究IEnumerable和IQueryable]以下都是个人理解,仅供参考,如有错误欢迎指出~ 在EF里面,使用IQueryable和IEnumerable可以延迟加载. IQueryba ...
- LINQ to Entities 不识别方法“System.Nullable`1[System.Int32] DiffDays(System.Nullable`1[System.DateTime], System.Nullable`1[System.DateTime])”,因此该方法无法转换为存储表达式。
解决方案: db.table.Where(m=>System.Data.Objects.EntityFunctions.DiffDays(m.CreateTime, DateTime.Now) ...
随机推荐
- 一些简单的Js代码的封装
1 function getById(id) { 2 3 } 4 5 function getAttr(el, k) { 6 7 } 8 9 function setAttr(el, k, v) { ...
- ES6初识-函数扩展
默认值 function test(x,y='world'){ console.log('默认值'); } function test2(...arg){ for(let v of arg){ con ...
- 用struct LNode *L与LinkList &L的区别
用void InitList(struct LNode *L), 函数InitList中如果改变了L指针本身的值,对其他函数无影响.用void InitList(LinkList &L),函数 ...
- Percona-Tookit工具包之pt-pmp
Preface Sometimes we need to know the details of a program(porcess) when it is running even ...
- 如何快速查看mysql数据文件存放路径?
进入mysql终端 mysql>show variables like '%datadir%'; 出来的结果即是!
- Ubuntu下安装libpcap+测试安装
1.从ftp://ftp.gnu.org/gnu/下载flex.bison.GNU M4.libpcap安装包,具体的链接分别如下: flex下载:http://flex.sourceforge.ne ...
- python3 练习题100例 (二十)
#!/usr/bin/env python3# -*- coding: utf-8 -*-"""练习二十:判断一个年份是否是闰年公历闰年计算方法:1.普通年能被4整除且不 ...
- Codeforces Round #449 (Div. 2) C. DFS
C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- realloc函数的用法
realloc(void *__ptr, size_t __size):更改已经配置的内存空间,即更改由malloc()函数分配的内存空间的大小. 如果将分配的内存减少,realloc仅仅是改变索引的 ...
- python基础之正则表达式爬虫应用,configparser模块和subprocess模块
正则表达式爬虫应用(校花网) 1 import requests 2 import re 3 import json 4 #定义函数返回网页的字符串信息 5 def getPage_str(url): ...