转换为CSV的子表上的LINQ排序

转换为CSV的子表上的LINQ排序,linq,linq-to-sql,Linq,Linq To Sql,我有一个EF模型(注意为了清晰起见将部分类连接在一起) 公共类产品 { public System.Guid ProductID{get;set;} 公共字符串乘积{get;set;} 公共虚拟ICollection模块{get;set;} [未映射] 公共字符串模块CSV { 得到 { 字符串retList=“”; foreach(模块中的模块aModule) { 如果(retList.Length>0) retList+=“,”; retList+=aModule.Module.Trim()

我有一个EF模型(注意为了清晰起见将部分类连接在一起)

公共类产品
{
public System.Guid ProductID{get;set;}
公共字符串乘积{get;set;}
公共虚拟ICollection模块{get;set;}
[未映射]
公共字符串模块CSV
{
得到
{
字符串retList=“”;
foreach(模块中的模块aModule)
{
如果(retList.Length>0)
retList+=“,”;
retList+=aModule.Module.Trim();
}
返回列表;
}
}
}
现在,我需要对CSV以及其他列进行排序,我意识到与sql的链接有问题。我的普通人做不到这一点,我想知道是否有人知道一个很好的方法来做这件事va LINQ,请分享一下

当前的排序行中,“sort”是列名,“sortdir”是“ASC”或“DESC”,用于处理其他列。
query=db.Products.AsExpandable().Where(谓词).OrderBy(sort+“”+sortdir)

不漂亮或效率不高,但 if(sort!=“CSV”)//作为非ddb列必须在列表中排序 query=db.Products.AsExpandable().Where(谓词).OrderBy(sort+“”+sortdir); 其他的 { query=db.Products.AsExpandable().Where(谓词)

if(sortdir==“ASC”)
{
query=db.Products.AsExpandable().Where(谓词).ToList().AsQueryable();
query=query.OrderBy(r=>r.GetType().GetProperty(sort).GetValue(r,null));
}
其他的
{
query=db.Products.AsExpandable().Where(谓词).ToList().AsQueryable();
query=query.OrderByDescending(r=>r.GetType().GetProperty(sort).GetValue(r,null));
}
}
public class Product
{
    public System.Guid ProductID { get; set; }
    public string Product{ get; set; }
    public virtual ICollection<Module> Modules { get; set; }
    [NotMapped]
    public string ModulesCSV
    {
        get
        {
            string retList = "";
            foreach (Module aModule in Modules)
            {
                if (retList.Length > 0)
                    retList += ", ";
                retList += aModule.Module.Trim ();
            }
            return retList;
        }
    }
 }
            if (sortdir=="ASC")
            {
                query = db.Products.AsExpandable().Where(predicate).ToList<Product>().AsQueryable <Product> ();
                query = query.OrderBy(r => r.GetType().GetProperty(sort).GetValue(r, null));
            }
            else
            {
                query = db.Products.AsExpandable().Where(predicate).ToList<Product>().AsQueryable <Product> ();
                query = query.OrderByDescending(r => r.GetType().GetProperty(sort).GetValue(r, null));
            }
        }