NHibernate返回Dictionary< int,string>

问题描述:

是否可以从nhibernate查询返回Dictionary < int,string>

Is it possible to return Dictionary<int, string> from an nhibernate query such as this:

CreateQuery("select CustomerId, FullName from Customer")  

我从这个论坛尝试了一些例子,使用.net ToDictionary方法,但是无法让它们工作。

I've tried a few examples from this forum using the .net ToDictionary method, but am unable to get them to work.

您需要在列表或枚举上执行以下操作,您应该得到dictonary

You need to do the following on your list or enumerable and you should get the dictonary

.ToDictionary(x => x.CustomerId, x => x.FullName);