在具有单个字符串属性的简单引用类型的大序列中搜索Diana有一个有趣的结果.
using System;
using System.Collections.Generic;
using System.Linq;
public class Customer{
public string Name {get;set;}
}
Stopwatch watch = new Stopwatch();
const string diana = "Diana";
while (Console.ReadKey().Key != ConsoleKey.Escape)
{
//Armour with 1000k++ customers. Wow, should be a product with a great success! :)
var customers = (from i in Enumerable.Range(0, 1000000)
select new Customer
{
Name = Guid.NewGuid().ToString()
}).ToList();
customers.Insert(999000, new Customer { Name = diana }); // Putting Diana at the end :)
//1. System.Linq.Enumerable.DefaultOrFirst() …Run Code Online (Sandbox Code Playgroud) 我有一个EF查询,我通过它的唯一标识符返回一个'Item'.我正在使用MVC提供的脚手架控制器,这可以正常工作,但现在我希望它返回属于该项目的标签列表.
我想我可以使用如下所示的'Include'来急切地获取标签.但是,使用异步时似乎不允许这样做.
Item item = await db.Items.Include("Tags").FindAsync(id);
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么这不起作用并建议另一种方法来恢复项目的标签?
干杯
本