惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
B
Blog
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
博客园 - 【当耐特】
D
DataBreaches.Net
Apple Machine Learning Research
Apple Machine Learning Research
阮一峰的网络日志
阮一峰的网络日志
I
InfoQ
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
量子位
美团技术团队
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
O
OpenAI News
SecWiki News
SecWiki News
A
About on SuperTechFans
J
Java Code Geeks
B
Blog RSS Feed
Y
Y Combinator Blog
L
LangChain Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Martin Fowler
Martin Fowler
博客园 - 聂微东
雷峰网
雷峰网
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
T
The Exploit Database - CXSecurity.com
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Palo Alto Networks Blog
Blog — PlanetScale
Blog — PlanetScale
N
News | PayPal Newsroom
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
F
Full Disclosure
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Hacker News
The Hacker News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
U
Unit 42
博客园_首页
T
Tailwind CSS Blog
T
Tenable Blog

博客园 - 阿修

Entity FrameWork 单表对多实体 让Entity Framework启动不再效验__MigrationHistory表 Linux+Mono+WebService:CS1703: An assembly with the same identity--mscorlib 获取某年中第几个礼拜的第一天的函数 DataTable.Rows.Remove(row) 与 DataTable.Rows[i].Delete()区别 [转摘]Lucene学习总结之一:全文检索的基本原理 Lucene.net根据Sort走到了不同的类处理 VPN Connections and Default Gateways - 阿修 牛!帮EXE等执行文件压缩的工具 进程通讯的多种方式 三星I9008删除程序清单 .NET编程中的部分效率问题 质量保证漫漫谈之QA、QC、QM的关系与区别 敏捷宣言 多维角度聊聊结对编程 在Windows下编译和.NET运行MemCached Serv-U服务器中文乱码问题的解决 请小心 管理学中四件不要做的事情
Entity Framework搜索指定字段解决方案
阿修 · 2013-08-12 · via 博客园 - 阿修
public class Book
{
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required, MaxLength(50)]
        public string Title { get; set; }
        public Double? Price { get; set; }
}

解决方案一:

var bkList = db.Books.Select(allBooks => new { Id = allBooks.Id, Title = allBooks.Title }).Select(b => new Book { Id=b.Id,Title=b.Title});

解决方案二:

var bkList2 = db.Books.Select(allBooks => new { Id = allBooks.Id, Title = allBooks.Title }).ToList().ConvertAll<Book>(b => new Book(){ Id=b.Id,Title=b.Title});

解决方案三:

//声明一个与Book一模一样的克隆类
public class BookClone
{
    public int Id { get; set; }

    public string Title { get; set; }

    public Double Price { get; set; }
}

var bkList3 = db.Books.Select(allBooks => new BookClone { Id = allBooks.Id, Title = allBooks.Title });

这三种方案都可以解决The entity or complex type '{0}' cannot be constructed in a LINQ to Entities query. 的异常