First: How to only get one result per group I already showed you in your previous question. Combined with an anonymous type this would look like the following:
SoleColorService.All()
.GroupBy(t => t.Sole.Code)
.Select(g => g.First())
.Select(x => new
{
SoleCode = x.Sole.Code,
SoleName = x.Sole.Name),
SoleId = x.SoleID)
});
Second: If you need to return the result of this query in a strong typed manner from your method you can't use an anonymous type. You will have to create a named type and use that instead:
public class SoleModel
{
private readonly string _code;
private readonly string _name;
private readonly int _id;
public SoleModel(string code, string name, int id)
{
_code = code;
_name = name;
_id = id;
}
public string Code { get { return _code; } }
public string Name { get { return _name; } }
public int Id { get { return _id; } }
}
SoleColorService.All()
.GroupBy(t => t.Sole.Code)
.Select(g => g.First())
.Select(x => new SoleModel(x.Sole.Code, x.Sole.Name x.SoleID));
Third: Assigning a list of anonymous types to a datasource should work.
var result = SoleColorService.All()
.GroupBy(t => t.Sole.Code)
.Select(g => g.First())
.Select(x => new
{
SoleCode = x.Sole.Code,
SoleName = x.Sole.Name),
SoleId = x.SoleID)
});
someControl.DataSource = result;