C# 不确定linq to sql查询的返回类型

C# 不确定linq to sql查询的返回类型,c#,sql,asp.net,linq,C#,Sql,Asp.net,Linq,我有一个方法: public static ???? GetUserProfile(Guid guid) { var UserProfileContext = new DataContext.UserProfileDataContext(); var UserProfile = (from p in UserProfileContext.aspnet_Profiles join u in

我有一个方法:

public static ???? GetUserProfile(Guid guid) {

            var UserProfileContext = new DataContext.UserProfileDataContext();
            var UserProfile = (from p in UserProfileContext.aspnet_Profiles
                              join u in (from u in UserProfileContext.aspnet_Users 
                                         where u.UserId == guid select u)
                              on p.UserId equals u.UserId
                              select new
                              {
                                  u.UserId,
                                  u.DisplayName,
                                  u.AvatarPath,
                                  u.LastActivityDate,
                                  u.Votes,
                                  u.Cures,
                                  u.LinkTitle,
                                  u.LinkURL,
                                  p.AboutMe
                              }).ToList();
            return UserProfile;
        }
我知道我可能需要返回一些东西的列表,但是什么

另外,我可能写错了查询。我正在尝试加入用户集上的一个配置文件表,其中user.UserID==传递的guid参数


提前谢谢。

这是匿名类型。
因为它没有名字,所以您不能返回它


相反,您应该使用这些属性创建自己的类,然后将其返回。

您可以将返回类型设置为动态。

您已经创建了一个匿名类型对象,可以将其作为对象或动态类型返回。但另一种方法是使用所需字段创建一个新类并返回该类型,如下所示:

public class MyModel
{
    int UserId{ get; set; }
    string DisplayName { get; set; }
    string AvatarPath { get; set; }
    DateTime LastActivityDate { get; set; }
    int Votes { get; set; }
    int Cures { get; set; }
    string LinkTitle { get; set; }
    string LinkURL { get; set; }
    string AboutMe { get; set; }
}
...
public static List<MyModel> GetUserProfile(Guid guid)
{
    var UserProfileContext = new DataContext.UserProfileDataContext();
    var UserProfile = (from p in UserProfileContext.aspnet_Profiles
                          join u in (from u in UserProfileContext.aspnet_Users 
                              where u.UserId == guid select u)
                          on p.UserId equals u.UserId
                          select new MyModel
                          {
                              UserId = u.UserId,
                              DisplayName = u.DisplayName,
                              AvatarPath = u.AvatarPath,
                              LastActivity = u.LastActivityDate,
                              Votes = u.Votes,
                              Cures = u.Cures,
                              LinkTitle = u.LinkTitle,
                              LinkURL = u.LinkURL,
                              AboutMe = p.AboutMe
                          }).ToList();
    return UserProfile;
}
公共类MyModel
{
int UserId{get;set;}
字符串DisplayName{get;set;}
字符串AvatarPath{get;set;}
DateTime LastActivityDate{get;set;}
整数投票{get;set;}
int治愈{get;set;}
字符串LinkTitle{get;set;}
字符串链接URL{get;set;}
字符串AboutMe{get;set;}
}
...
公共静态列表GetUserProfile(Guid)
{
var UserProfileContext=new-DataContext.UserProfileDataContext();
var UserProfile=(来自UserProfileContext.aspnet\u Profiles中的p
加入(从UserProfileContext.aspnet\u用户中的u加入)
其中u.UserId==guid选择u)
在p.UserId上等于u.UserId
选择新的MyModel
{
UserId=u.UserId,
DisplayName=u.DisplayName,
AvatarPath=u.AvatarPath,
LastActivity=u.LastActivityDate,
选票=美国选票,
治疗=美国治疗,
LinkTitle=u.LinkTitle,
LinkURL=u.LinkURL,
AboutMe=p.AboutMe
}).ToList();
返回UserProfile;
}

总之,你的选择是:
List
List
List
List

,这是一种匿名类型。您不能返回它。那么有什么解决方案吗?在强类型语言中,这既不是一种好的编程风格,也不是必需的。在这种情况下,最好创建一个非匿名类,它仍然是一个有效的选项。我本可以重复其他答案,但那会很枯燥。