Tag: linq

如何将IEnumerable <Task >转换为IObservable

是否有内置的方法将IEnumerable <Task >转换为IObservable 。 顺序并不重要,只是我得到的东西,但最好是因为它们已经完成。 如果它还不存在,那么实现它的好方法是什么?

LINQ Select与List不同?

我有以下列表: class Person { public String Name { get; set; } public String LastName { get; set; } public String City { get; set; } public Person(String name, String lastName, String city) { Name = name; LastName = lastName; City = city; } } … personList.Add(new Person(“a”, “b”, “1”)); personList.Add(new Person(“c”, “d”, “1”)); personList.Add(new Person(“e”, […]

entity framework – 包含导航属性的选择条件

假设我有这些简化的EF生成实体…… public class PurchaseOrder { public int POID {get;set;} public int OrderID {get;set;} public int VendorID {get;set;} public IEnumerable Orders {get;set;} } public class Order { public int OrderID {get;set;} public decimal Price {get;set;} public IEnumerable Items {get;set;} } public class Item { public int OrderID {get; set;} public string SKU {get;set;} public int VendorID […]

LINQ:如何从IQueryable 中删除元素

你如何循环IQueryable并删除一些我不需要的元素。 我正在寻找这样的东西 var items = MyDataContext.Items.Where(x => x.Container.ID == myContainerId); foreach(Item item in items) { if(IsNotWhatINeed(item)) items.Remove(item); } 可能吗? 提前致谢

为什么有JConstructor?

Json.NET定义了一个JConstructor类型 。 这很令人困惑,因为(据我所知)构造函数不是JSON的一部分。 我仔细检查了JSON规范并浏览了json.org但却找不到任何东西。 网上任何地方似乎都没有关于此类型的文档。 因为Json.NET被如此广泛地使用(它甚至由微软委托),我认为必须有一些合理的动机将这种表示包含在对象模型中。 问题是,我决定动机的任何尝试都只是猜测。 我测试了类型及其序列化,明显的行为是只包装JavaScript代码,例如new constructorName(…) ,例如: new JConstructor(“ctorExample”, new JValue(“value”), new JObject( new JProperty(“prop1”, new JValue(1)), new JProperty(“prop2”, new JValue(2))) ) .ToString() 输出 new ctorExample( “value”, { “prop1”: 1, “prop2”: 2 } ) 那么, JConstructor类型旨在表示什么以及它为什么存在?

如何在C#中使用Linq对OrderedDictionary进行排序(使用.NET 3.5)?

我需要对OrderedDictionary进行排序(System.Collections.Specialized)我有这样的代码: var od = new System.Collections.Specialized.OrderedDictionary(); od.Add(“a1”, 3); od.Add(“a2”, 5); od.Add(“a3”, 2); od.Add(“a4”, 4); 我希望使用值对其进行排序。 我可以使用Linq吗?

LINQ中长和类的求和方法

如何获得长类型的一些项目的总和…这是mycode: using (gEn myEntities = new gEn) { var load = (from items in myEntities.Orders select items.PayO).DefaultIfEmpty(0).Sum(); } 但是Sum给了我int …我也想知道当使用long类型时,DefaultIfEmpty方法是否与Sum方法有任何冲突…提前感谢…

使用DateDiff和Linq.Dynamic库获取今天的记录

我试图通过MVC 5 / Entity Framework 6应用程序中的Linq表达式使用DateDiff SQL语法获取今天添加的所有记录。 DateDiff函数抛出运行时错误 实际上我想用以下linq WHERE子句来解析linq动态 .Where(p => DbFunctions.DiffDays(p.added_date, DateTime.Now) == 0) 为了获取今天添加的记录。 我正在使用的示例代码如下所示 var _list = new vsk_error_log(); using (var entities = new vskdbEntities()) { _list = entities.vsk_error_log //.Where(“DateDiff(DAY,added_date,getdate())=0”) .Where(p => DbFunctions.DiffDays(p.added_date, DateTime.Now) == 0) .ToList(); } return _list; 关于Linq.Dynamic表达式 – 如何编写where子句 LINQ中的动态WHERE子句

而不是货币符号我在命令提示符中得到一个问号

我使用的是Windows 7,Visual Studio 2013,C#和.NET 4.5。 我的问题是以下行的输出: Console.WriteLine(“Car`s value: {0:C} “, myNewCar.determineMarketValue()); myNewCar.determineMarketValue()返回一个double。 我该如何解决这个问题? 我的输出是这样的: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lesson15SimpleClasses { class Program { static void Main(string[] args) { Car myNewCar = new Car(); myNewCar.Make = “Oldsmobile”; myNewCar.Model = “Cutlas Supreme”; myNewCar.Year = 1986; myNewCar.Color = “Silver”; Console.OutputEncoding = […]

对并发集合线程的linq操作是否安全?

例如以下代码线程安全: ConcurrentQueue _queue = new ConcurrentQueue(); while(true) { for(int y = 0; y _queue.Enqueue(Guid.NewGuid())); } else if (y % 3 == 1) { Guid x; System.Threading.Tasks.Task.Run(() => _queue.TryDequeue(out x)); } else if(y % 3 == 2) { System.Threading.Tasks.Task.Run(() => { if (_queue.Any(t => t == testGuid)) { // Do something } }); } } 编辑:显然标题不够清晰,所以更新代码示例以包含实际的multithreading行为,是的,上面的代码只是multithreading行为的示例 […]