I have a simple request as below
var trips = from t in ctx.Trips select t;
The problem is that I have an additional property in the Trip object that needs to be assigned, preferably without repeating through the returned one IQueryable.
IQueryable
Does anyone know how to set a value during a query? (i.e. select t, t.property = "value")
First of all, if you never repeat the results, your code will not work. LINQ is "lazy," which means it computes the next result when you request it.
, , , - :
Trip SetProperty(Trip t) { t.property = "value"; return t; } var trips = from t in ctx.Trips select SetProperty(t);
:
var trips = from t in ctx.Trips select new Trip { // db properties t.ID, t.Name, t.Description, // non-db properties SomeValue = 45, SomeOtherValue = GetValueFromSomewhereInCode(t.ID) }
"" Trip, , LINQ to SQL, . , , SQL, .
Trip , ( SubmitChanges(), Trip).
SubmitChanges()
Trip
, Trip LINQ to SQL. , .
Trips, .
, Trips , , , where.
, ..
LINQ to SQL :
using (var context = new DefaultDataContext()) { var defects = context.Defects.Where(d => d.Status==Status.Open); foreach(Defect d in defects) { defect.Status = Status.Fixed; defect.LastModified = DateTime.Now; } context.SubmitChanges(); }
Source: https://habr.com/ru/post/1732952/More articles:Pagination script error - Why are you jumping to the first page? - phpSQL5043N Support for one or more communication protocols failed - db2Limit the number of items in a list in WinForms - c #JSP or RUBY / PHP? - phpStruggle with model relationships - model-view-controllerjquery overlay ajax form post - jqueryhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1732954/subscription-webdesktop-app-python&usg=ALkJrhiT9bOaFYb_CnN4iEl-wb_5s48GSgAutocomplete search component for text fields in ASP.NET - javascript"Заполнение недопустимо и не может быть удалено" - не так ли с этим кодом? - c#What is in memory location 1 on an Intel x86 computer running Windows XP? - assemblyAll Articles