0

I am using C# and LINQ and trying to combine two sets of data. The first is a List of a specific type, lets call this Status (List) which is just a class with a bunch of properties one of which includes a comma separated value list of accounts. This is queried from the application database using a stored procedure so I have some flexability as to what is displayed here

For example:

class Status
{
   ...
   public string Accounts {get; set;} (ie. "abcde, qwerty, asdfg")
   public string Managers {get; set;}
   ...
}

The rest of the properties are irrelevant as this is the only field I am joining on.

The second "Accounts" data set is from a web service which I am calling to get a list of "Accounts" and the people associated with each account.

For example:

Account    Manager                 SomeData   MoreFields     ...
-------    -------------------     --------   ----------     ---
abcde      Bob Marley              Data       MoreData       ...
qwerty     Fred Flinstone          Data       MoreData       ...

So bascially I need to Create a list of Status objects with a CSV list of Manager(s) from the Accounts dataset in the Managers property of Status. Problem is I have no control over what is retruend in this dataset as it is a third party application. So I need to find some way to do this without modifying the "Accounts" data. Unless I do something in memory after getting the dataset from the web service.

I hope this makes sense and I thank you in advance!


EDIT: As usr points out in his answer Dictonary.Count is not thread-safe. The documentation says:

enumerating through a collection is intrinsically not a thread-safe procedure. In the rare case where an enumeration contends with write accesses, the collection must be locked during the entire enumeration.

Which means synchronization is required. Note that the same lock needs to be used by any other code that may be modifying the collection. This is highly error prone, if the Dictionary is used by multiple threads consider using ConcurrentDictionary instead

4

1 回答 1

0

你所说的这个“数据集”是什么?我不在乎它来自哪里——我只关心它在 C# 中是什么类型的对象。

我将假设它是一个 ICollection,称为“帐户”

接下来,我将假设 Managers 是一个与 Accounts 非常相似的 CVS 列表。

此外,我将只创建一个状态对象而不是它们的“列表”,因为您永远不会说出将一种状态与另一种状态区分开来的原因。

var status = new Status();
status.Accounts = string.Join( ", ", from k in accounts select k.Account);
status.Managers = string.Join( ", ", from k in accounts select k.Manager);
于 2012-12-07T22:55:06.093 回答