C# 更新作为参数传递给方法的实体对象的值
我有一个传递给方法的查询对象C# 更新作为参数传递给方法的实体对象的值,c#,object,pass-by-reference,pass-by-value,C#,Object,Pass By Reference,Pass By Value,我有一个传递给方法的查询对象 using (var ctx = new AH_ODS_DBEntities1()) { var orlist = ctx.Collections.Where(x => x.AQ_PostStatus == 0).GroupBy(x => x.SourceOR).Select(x => new { Key = x.Key }).ToList(); foreach(var ordocnumber in orlist) // navi
using (var ctx = new AH_ODS_DBEntities1())
{
var orlist = ctx.Collections.Where(x => x.AQ_PostStatus == 0).GroupBy(x => x.SourceOR).Select(x => new { Key = x.Key }).ToList();
foreach(var ordocnumber in orlist) // navigate the list of OR's
{
Console.WriteLine(ordocnumber.Key);//+"\n"+fatnotes+"\n");
var orcontents = ctx.Collections.Where(dx => dx.SourceOR == ordocnumber.Key).ToList().Select(dx =>
new Collection
{
AmountPaid = dx.AmountPaid,
ApplicationDate = dx.ApplicationDate,
AQ_Branch = dx.AQ_Branch,
AQ_PostStatus = dx.AQ_PostStatus,
AQ_StatusDate = dx.AQ_StatusDate,
CashAccount = dx.CashAccount,
CustomerCode = dx.CustomerCode,
Description = dx.Description,
DocumentType = dx.DocumentType,
DTS = dx.DTS,
ExtSerial = dx.ExtSerial,
PaymentMethod = dx.PaymentMethod,
Serial = dx.Serial,
SourceBranch = dx.SourceBranch,
SourceInvoice = dx.SourceInvoice,
SourceOR = dx.SourceOR,
TotalAmountPaid = dx.TotalAmountPaid,
Type = dx.Type
});
AQEngine2(context, orcontents); // i will do some stuff here
ctx.SaveChanges();
}
}
O将Or内容传递给方法AQEngine2(上下文,Or内容)。在方法内部,我浏览对象并更新其属性:
public static void AQEngine2(KDICOLLECTIONS.Screen context, IEnumerable<Collection> orcontents){
Boolean HasError = false;
foreach (var subitem2 in orcontents) // naviagte through the selected OR and fill-up the stuff for AQ
{
if (HasError)
{
subitem2.AQ_PostStatus = -1;
}
}
}
publicstaticvoidaqengine2(KDICOLLECTIONS.Screen上下文、IEnumerable或contents){
布尔hasrerror=false;
foreach(orcontents中的var子项2)//导航选定的OR并填充AQ的内容
{
if(hasrerror)
{
子项2.AQ_PostStatus=-1;
}
}
}
我希望更新能够反映回呼叫过程。我试着添加ref-IEnumerable或content,但它不起作用
返回值的正确方法是什么
谢谢,如果理解问题背后的问题,那么这个问题已经有答案了:谢谢@OgnyanDimitrov