linq

How to resolve Value cannot be null. Parameter name: source in linq?

久未见 提交于 2021-02-04 10:15:39
问题 I don't know why I get this kind of error. It happens sometimes, and I suspicious of my code that still have thread running while I close my Application. So when I open again it happens. Value cannot be null. Parameter name: source StackTree : at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate) at Susenas2015.ViewModels.Kuesioner.VMVsen15_KVal.SettingValidationAndRange(List`1 listTextBox, List`1 listCheckBox, TabControl tabControl) in d:\handita\Office\Project

How to resolve Value cannot be null. Parameter name: source in linq?

风格不统一 提交于 2021-02-04 10:15:26
问题 I don't know why I get this kind of error. It happens sometimes, and I suspicious of my code that still have thread running while I close my Application. So when I open again it happens. Value cannot be null. Parameter name: source StackTree : at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate) at Susenas2015.ViewModels.Kuesioner.VMVsen15_KVal.SettingValidationAndRange(List`1 listTextBox, List`1 listCheckBox, TabControl tabControl) in d:\handita\Office\Project

How to resolve Value cannot be null. Parameter name: source in linq?

瘦欲@ 提交于 2021-02-04 10:15:24
问题 I don't know why I get this kind of error. It happens sometimes, and I suspicious of my code that still have thread running while I close my Application. So when I open again it happens. Value cannot be null. Parameter name: source StackTree : at System.Linq.Enumerable.Where[TSource](IEnumerable`1 source, Func`2 predicate) at Susenas2015.ViewModels.Kuesioner.VMVsen15_KVal.SettingValidationAndRange(List`1 listTextBox, List`1 listCheckBox, TabControl tabControl) in d:\handita\Office\Project

【C#】异步的用法

拈花ヽ惹草 提交于 2021-02-04 02:39:23
1. C#5.0 加入了async, await关键字. async 是在声明异步方法时使用的修饰符, 声明放在返回值之前即可, await 表达式则负责消费异步操作, 不能出现在catch或finally块, 非异步匿名函数(没有用async声明的匿名方法或者lambda表达式), lock语句或不安全的代码中使用。 ps:这些约束条件是为了保证安全,特别是关于锁的约束。如果你希望在异步操作完成时持有锁,那么应该重新设计你的代码。不要通过在 try/finally 块中手动调用 Monitor.TryEnter 和 Monitor.Exit 的方式绕过编译器的限制,而应该实现代码的更改,这样在操作过程中就不再需要锁了。如果此时的情况不允许代码的改变,则可考虑使用 SemaphoreSlim 和它的 WaitAsync 方法来代替。 2. 所有用async修饰的异步方法, 参数都不可以使用out 或者 ref 修饰符. 返回值必须是void, task, task<T>. 一般为task. 因为可以让调用者监控异步操作的状态. 3. await的主要目的是在等待耗时操作完成时避免阻塞。代码总是在执行到await的时候就开始返回了, 并且到达await之后会校验结果是否存在 如果结果不存在, 会安排给一个后续操作, 这个后续操作会记录位置,状态, 然后代码回到UI主线程继续运行,

VS添加版权声明

旧时模样 提交于 2021-02-02 21:15:31
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\ItemTemplates\AspNetCore\Code\1033\Class 1 /* 2 *┌────────────────────────────────────────────────┐ 3 *│ 描 述:$safeitemrootname$ 4 *│ 作 者:fanqi 5 *│ 版 本:1.0 6 *│ 创建时间:$time$ 7 *└────────────────────────────────────────────────┘ 8 */ 9 10 using System; 11 using System.Collections.Generic; 12 using System.Linq; 13 using System.Threading.Tasks; 14 15 namespace $rootnamespace$ 16 { 17 public class $safeitemrootname$ 18 { 19 } 20 } 21 22 ////////////////////////////////////////////////////////////////// // 23 // _ooOoo_ // 24

《Effective C#》笔记(4)

我与影子孤独终老i 提交于 2021-02-02 00:38:24
优先考虑提供迭代器方法,而不要返回集合 在创建这种返回一系列对象的方法时,应该考虑将其写成迭代器方法,使得调用者能够更为灵活地处理这些对象。 迭代器方法是一种采用yield return语法来编写的方法,采用按需生成(generate-as-needed)的策略,它会等到调用方请求获取某个元素的时候再去生成序列中的这个元素。 类似下面这个简单的迭代器方法,用来生成从0到9的int序列: public static IEnumerable<int> GetIntList() { var start = 0; while (start<10) { yield return start; start++; } } 对于这样的写法,编译器会用特殊的办法处理它们。然后在调用端使用方法的返回结果时,只有真正使用这个元素时才会生成,这对于较大的序列来说,优势是很明显的。 那么有没有哪种场合是不适宜用迭代器方法来生成序列的?比方说,如果该序列要反复使用,或是需要缓存起来,那么还要不要编写迭代器方法了? 整体来说,对于集合的使用,可能有两种情况: 只需在真正用到的时候去获取 为了让程序运行得更为高效,调用方需要一次获取全部元素 为了兼顾这两种场景,.net类库的处理方法,为IEnumerable<T>提供了ToList()与ToArray(),这两个方法就会根据所表示的序列自行获取其中的元素

Linq dynamic having issue with double quote

强颜欢笑 提交于 2021-01-29 18:39:25
问题 I am using System.Linq.Dynamic; to generate dynamic linq query which featch records from db context. I generate where clause in string format for dynamic linq, It works perfectly if input does not have any double quote. However, it throws error once input string contains double quote. I followed Stack Overflow existing solution dynamiclinq-escaping-double-quotes-inside-strings but it does not helped because I wanted to use LIKE operator. I'm using Contains condition in my where clause because

xdocument descendantsnodes vs nodes

好久不见. 提交于 2021-01-29 18:14:18
问题 I'm trying to understand the difference between the extension method, DescendantsnNodes and the method, "Nodes" of the class XDocument. I can see that the DescendantsNodes should return all descendants of this document or element and Nodes should return all child nodes of this document or element. I don't understand what's the difference between "all child nodes" and "all descendants". could someone please clarify this? 回答1: A child node would be a node which is directly "underneath" a

Joining two tables in EF Core, invalid column name

流过昼夜 提交于 2021-01-29 17:59:46
问题 I am trying to join two tables in EntityFramework Core using linq syntax in the following way: var results = dc.EntityA.Join(dc.EntityB, a => a.StringProperty, b => b.StringProperty, (a, b) => DoSomeStuff(a, b)).ToList(); Where StringProperty is a string column in the database. I am getting the error {"Invalid column name 'EntityId'."} I found this similar question Entity Framework: Invalid column name 'OrganizationStructure_ID' where it is suggested to set the foreignkeys during

"Violation of PRIMARY KEY constraint '…'. Cannot insert duplicate key in object

送分小仙女□ 提交于 2021-01-29 16:30:48
问题 I just started to make my first project with Codefirst-Approach with C#, Linq and MSSQLSERVER and run into an problem when trying to insert a new DB-entry that contains an reference to an already existing element from another table. InnerException {"Violation of PRIMARY KEY constraint 'PK_dbo.Manufacturers'. Cannot insert duplicate key in object 'dbo.Manufacturers'. The duplicate key value is (1d262e43-b9b6-4752-9c79-95d955d460ab).\r\nThe statement has been terminated."} System.Exception