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 リストであると仮定します。

さらに、ステータス オブジェクトの「リスト」ではなく、ステータス オブジェクトを 1 つだけ作成します。

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 に答える