I have a linq to sql method, and when it executes the query, it returns some anonymous type.
I want to return this anonymous type back to my service level in order to do some kind of logic and stuff.
I don't know how to get it back though.
I thought I could do it
public List<T> thisIsAtest()
{
return query;
}
but i get this error
Error 1 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)
So I'm not sure which build I am missing, or even if it is.
thanks
EDIT
Well, my first problem was resolved, but now I have a new problem that I'm not sure how to fix, since I know little about anonymous types.
I get this error
It is not possible to implicitly convert the type 'System.Collections.Generic.List' to 'System.Collections.Generic.List
Here is the request
DbContext.Table.Where(u => u.Table.UserId == userId && u.OutOFF != 0)
.GroupBy(u => new { u.Table.Prefix })
.Select(group => new { prefix = group.Key,
Marks = group.Sum(item => (item.Mark * item.Weight) / item.OutOFF) })
.ToList();
Edit 2
public class ReturnValue
{
string prefix { get; set; }
decimal? Marks { get; set; }
}
public List<ReturnValue> MyTest(Guid userId)
{
try
{
var result = dbContext.Table.Where(u => u.Table.UserId == userId && u.OutOFF != 0).GroupBy(u => new { u.Table.Prefix })
.Select(group => new { prefix = group.Key, Marks = group.Sum(item => (item.Mark * item.Weight) / item.OutOFF) }).ToList();
return result;
}
catch (SqlException)
{
throw;
}
this element has this
Anonymous Types:
a is new{string Prefix}
b is new{ 'a prefix, decimal? marks}