我以以下形式获取数据:
[0]: { rkey = "100asb", pkey = "100ap0", ckey = {1/6/2013 3:28:09 AM} }
[1]: { rkey = "yxq4c", pkey = "100iis", ckey = {1/6/2013 6:38:48 PM} }
.
.
.
我必须编写另一个可以访问值的方法rkey
,pkey
并且ckey
。不幸的是,我无法以线性ForEach
或Parallel.ForEach
. 我已经搜索过,但我还没有找到访问我的参数的解决方案。有些人建议将其转换为 a Dictionary
,但我不确定这是否是一条好路。它必须比这简单得多。
我写的代码是这样的:
var films = myrollup.GetCompletedMovies(dtstart, dtend).Result;
using (var session = factory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
Parallel.ForEach(films, currentFilm =>
{
dynamic f = currentFilm;
lock (myrollup)
{
var user = User.GetAsync(f.pkey).Result;
var record = new FilmAnalytics()
{
UserID = currentFilm.pkey,
FilmID = currentFilm.rkey,
UserName = user.FirstName,
UserLastName = user.LastName,
UserAlias = user.Alias,
UserEmail = user.Email,
UserFacebook = user.FbEmail,
Dateofcompletion = currentFilm.ckey
};
session.SaveOrUpdate(record);
}
});
transaction.Commit();
}
}
该变量films
产生IEnumerable<dynamic>
类型数据。