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

推荐订阅源

大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
H
Help Net Security
P
Privacy & Cybersecurity Law Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Help Net Security
Help Net Security
Hugging Face - Blog
Hugging Face - Blog
D
Docker
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V2EX - 技术
V2EX - 技术
人人都是产品经理
人人都是产品经理
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google Online Security Blog
Google Online Security Blog
博客园 - 聂微东
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Blog — PlanetScale
Blog — PlanetScale
C
Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
爱范儿
爱范儿
Webroot Blog
Webroot Blog
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Register - Security
The Register - Security
Simon Willison's Weblog
Simon Willison's Weblog
A
Arctic Wolf
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
Y
Y Combinator Blog
Last Week in AI
Last Week in AI
S
Securelist
Cloudbric
Cloudbric
G
GRAHAM CLULEY
M
MIT News - Artificial intelligence
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Visual Studio Blog
S
Schneier on Security
Engineering at Meta
Engineering at Meta

博客园 - 阿修

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. 的异常