Using the Entity Framework and moving the DbContext to the class as follows:
public class Demo : IDisposable { internal DbContext context; internal int PrivateId = 5; public Demo() { this.context = new MyDbContext(); } public void Question() { //Is there going to be a problem using `this` in the predicate var issue = this.context.SomeTable.Where(st => st.ForeignKeyId == this.PrivateId); } public Dispose() { this.context.Dispose(); } }
It's as simple as I could think of. I was not sure if it thiswould be somehow changed or changed when used as part of the predicate for Where. Basically I just wanted to double check because I was not sure. I checked the reimplementation ofWhere Jon Skeet, but it’s still not entirely clear what will thiskeep its value.
this
Where
My ambiguity is due to the fact that predicates are transmitted as Funcwhen used with deferred execution. As a result, it would seem that the link to thiscan be used later, and not immediately after the call Where.
Func
this?
this ( ). this. , , this, .
, , , , - Demo. PrivateId . , PrivateId , - , .
Demo
PrivateId
Where, .
PrivateId , , - :
var idCopy = this.PrivateId; var issue = this.context.SomeTable.Where(st => st.ForeignKeyId == idCopy );
, this . , .
, :
var id = "12345"; var issue = this.context.SomeTable.Where(st => st.ForeignKeyId == id);
id Where? , , "12345".
id
this , . - Zip ForEach , this.IEnumerable - , Where Select .
Zip
ForEach
this.IEnumerable
Select
this. , "this", - , PrivateId.
public void Question() { //Is there going to be a problem using `this` in the predicate var issue = context.SomeTable.Where(st => st.ForeignKeyId == PrivateId); }
Source: https://habr.com/ru/post/1525862/More articles:Как заполнить пересечение двух объектов в Fabric.js? - javascriptМаксимальная сумма матрицы подматрицы NxN и с N-ненулевыми значениями, только O (N ^ 2) - algorithmКак Mercurial сливается внутри? - branching-and-mergingConditionally compile document sections in Sphinx - pythonIntegration with Android and MoPub - androidBetter to run 2 sql queries or 1 and deal with a duplicate result set? - databasehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1525864/why-use-bitshifts-when-setting-values-to-variables&usg=ALkJrhhyl2kcEcinWXyMouJ6vRRRzhtgDQIs performSelector: onThread: withObject: waitUntilDone: in order? - multithreadingsed add text obtained from stdout - bashHow would you handle different error responses for different routes using Laravel - phpAll Articles