0

I'm trying to retrieve a Dictionary as a return value from a query, and I haven't had much luck with the following:

IQuery query = session.CreateQuery("SELECT Email, COUNT(Id) as IdCount FROM AccountDataModel WHERE Email = :Email")
                        .SetParameter(":Email", model.Email); 

IList<T> list = query.List<T>();

IDictionary<string, object> data = list.ToDictionary<string, object>(x => x); //Error, no method argument matches.

The ToDictionary method asks for a type of Func. I found a definition for Func, here.

After seeing this, I tried the following:

list.ToDictionary<string, object>(y => y.As<string>().As<object>());

I receive an error in the process...

Is there a straight way to do this, or is it more of a hacky methodology which promotes it?

Community
  • 1
  • 1
Holland Schutte
  • 231
  • 2
  • 10

1 Answers1

0

I think you need to substitute the actual parametertype in the place of Generic typeParameter T in the code IList<T> list = query.List<T>();

something like IList<Email> list = query.List<Email>();

Then when you are calling the ToDictionary specify the key for it.ie.. IDictionary<string, Email> data = list.ToDictionary(x => x.emailId);

Ashley John
  • 2,379
  • 2
  • 21
  • 36