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

推荐订阅源

Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
T
Tenable Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
C
Cisco Blogs
A
Arctic Wolf
T
Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
Spread Privacy
Spread Privacy
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
SecWiki News
SecWiki News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
Scott Helme
Scott Helme
S
Securelist
AWS News Blog
AWS News Blog
Hacker News: Ask HN
Hacker News: Ask HN
美团技术团队
博客园 - 叶小钗
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
博客园_首页
H
Hacker News: Front Page
博客园 - 【当耐特】
J
Java Code Geeks
宝玉的分享
宝玉的分享
Jina AI
Jina AI
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cloudbric
Cloudbric
N
News and Events Feed by Topic
爱范儿
爱范儿
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
V
Visual Studio Blog
T
Troy Hunt's Blog
博客园 - 司徒正美
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
S
Secure Thoughts
L
LINUX DO - 热门话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - Franky
G
Google Developers Blog
Schneier on Security
Schneier on Security

博客园 - 阿修

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