return list with anonymous type in entity framework

后端 未结 6 1472
北恋
北恋 2021-01-02 07:21

How i can return list with anonymous type, because with this code i get

\"The type or namespace name \'T\' could not be found (are you missing a using directive or a

6条回答
  •  一整个雨季
    2021-01-02 07:53

    Scope of anonymous types are limited to the method in which they are defined. In your case, you better declare a separate class with the relevant properties and return a collection of the instances of that class. For e.g.

    public class UserDetail
    {
       public int Id{get;set;}
       public string UserName {get;set;}
    }
    
    public static List 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 UserDetail{ IdMember = row.IdMember, UserName = row.Profile_Information.UserName });
    
                return items.ToList();
            }
        }
    

提交回复
热议问题