In entity framework, return a list of anonymous types.

asp.net c# entity-framework linq

Question

How can I return a list with an anonymous type using this code?

Are you missing a using directive or an assembly reference? because "The type or namespace name 'T' could not be found."

I only need to get back IdMember and UserName.

    public static List<T> GetMembersItems(string ProjectGuid)
    {
        using (PMEntities context = new PMEntities("name=PMEntities"))
        {
            var items = context.Knowledge_Project_Members.Include("Knowledge_Project").Include("Profile_Information")
                        .Where(p => p.Knowledge_Project.Guid == ProjectGuid)
                        .Select(row => new { IdMember = row.IdMember, UserName = row.Profile_Information.UserName });

            return items.ToList();
        }
    }
1
9
8/4/2011 4:27:28 AM

Popular Answer

These kinds of circumstances call for the class Tuple<>. Although creating a custom class, as previously mentioned, is clearer, Tupple also works.

e.g.

.Select(row => new Tuple<int,string>(row.IdMember,row.Profile_Information.UserName))

You must use the following method to access the member properties on the opposite side of the wire:

var id=t.Item1
var name=t.Item2
11
1/5/2013 6:51:13 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow