Linq Query 中的缓存结果
Cached results in Linq Query
Edit: At first I thought this was related to component views, but I've managed to isolate the issue a bit.
我有以下 class:
public class TmpContext
{
public NYPContext db { get; set; }
public IEnumerable<SelectListItem> GetUserListFromSelection(int[] selection)
{
var userList = from u in db.UsuariosIntranet
join su in selection on u.Id equals su
select new SelectListItem()
{
Text = string.Format("{0}, {1}", u.ApellidoPaterno, u.Nombres),
Value = u.Id.ToString(),
};
return userList;
}
}
我有一个接收上面的 class 作为模型的视图,其中包含以下代码:
@{
// First list
var list1 = new int[] { 4947850 };
var a = Model.GetUserListFromSelection(list1);
foreach (var user in a)
{
<p class="tag">@user.Text</p>
}
// Second list, note the different ids
var list2 = new int[] { 2, 3 };
var b = Model.GetUserListFromSelection(list2);
foreach (var user in b)
{
<p class="tag">@user.Text</p>
}
// Third list
var o = list1.ToList();
// add a new id
o.Add(5185969);
// int[] otra = ;
var c = Model.GetUserListFromSelection(o.ToArray());
foreach (var user in c)
{
<p class="tag">@user.Text</p>
}
}
预期的结果是三个不同的列表,但不知何故我得到了第一个项目重复了三次。
这是预期的行为吗?
这似乎是一个错误,并且已经修复。谈论快速周转!
Edit: At first I thought this was related to component views, but I've managed to isolate the issue a bit.
我有以下 class:
public class TmpContext
{
public NYPContext db { get; set; }
public IEnumerable<SelectListItem> GetUserListFromSelection(int[] selection)
{
var userList = from u in db.UsuariosIntranet
join su in selection on u.Id equals su
select new SelectListItem()
{
Text = string.Format("{0}, {1}", u.ApellidoPaterno, u.Nombres),
Value = u.Id.ToString(),
};
return userList;
}
}
我有一个接收上面的 class 作为模型的视图,其中包含以下代码:
@{
// First list
var list1 = new int[] { 4947850 };
var a = Model.GetUserListFromSelection(list1);
foreach (var user in a)
{
<p class="tag">@user.Text</p>
}
// Second list, note the different ids
var list2 = new int[] { 2, 3 };
var b = Model.GetUserListFromSelection(list2);
foreach (var user in b)
{
<p class="tag">@user.Text</p>
}
// Third list
var o = list1.ToList();
// add a new id
o.Add(5185969);
// int[] otra = ;
var c = Model.GetUserListFromSelection(o.ToArray());
foreach (var user in c)
{
<p class="tag">@user.Text</p>
}
}
预期的结果是三个不同的列表,但不知何故我得到了第一个项目重复了三次。
这是预期的行为吗?
这似乎是一个错误,并且已经修复。谈论快速周转!