English 中文(简体)
阵列中的奇奇怪数值 - 在我改变后它们保持不变
原标题:Strange values in an array - after I change them they remain the same
  • 时间:2012-05-25 10:58:02
  •  标签:
  • c#
  • database

这是我的代码:

var items = tableInDatabase.All("WHERE [Order] > " + order);
foreach (var i in items.ToArray())
{
    i.Order = 7;
}
tableInDatabase.Save(items.ToArray());

However, when the breakpoint comes to the last line (after the foreach loop), every element of items has an order the same as before (not 7). Why is this happening? While still in the loop, i has an order of 7.

我使用大规模, 这是官方网页上的例子:

var table = new Products();
var drinks = table.All("WHERE CategoryID = 8");
foreach(var item in drinks.ToArray()){
    item.CategoryID = 12;
}
table.Save(drinks.ToArray());

我也试过:

foreach (var i in items.ToArray())
{
    tableInDatabase.Update(i, i.Id);
}

什么都没有

返回类型 od 表InDatabase 是类表InDatabase。这是定义 :

public TableInDatabase() : base(connectionString, "System.Data.SqlClient", "TableInDatabase", "Id") { }
最佳回答

使用此代码 :

var items = tableInDatabase.All("WHERE [Order] > " + order);
var array = items.ToArray();
foreach (var i in array)
{
    i.Order = 7;
}
tableInDatabase.Save(array);
问题回答

To Array () create a new option as said by Romil, "https://github.com/robconery/massive" rel= "nofollow" >Massive ,你也许可以按Adam的话做,但这个选项可以产生两个变量。你可以尝试以下两个变量。

var items = tableInDatabase.All("WHERE [Order] > " + order).ToArray();
foreach (var i in items)
{
    i.Order = 7;
}
tableInDatabase.Save(items);

这在大规模例子中是一个已知的问题,据报导这里





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签