C# 如何在linq c中使用子字符串#

C# 如何在linq c中使用子字符串#,c#,asp.net,sql-server,linq,c#-4.0,C#,Asp.net,Sql Server,Linq,C# 4.0,您好,我需要一个帮助,在我的liq代码中使用substring来获取一些保存在DB中的数据。我想在v.描述中使用 v、 Description.子字符串(0399)某物 这是我的密码 public static string BindeWorkOutDetails(int Id, Label Header, Label Title, Label Description) { DataClassesDataCont

您好,我需要一个帮助,在我的liq代码中使用substring来获取一些保存在DB中的数据。我想在v.描述中使用

v、 Description.子字符串(0399)某物

这是我的密码

public static string BindeWorkOutDetails(int Id, Label Header, 
                     Label Title, Label Description)
        {
            DataClassesDataContext con = 
                  new DataClassesDataContext(con);
            var q = (from v in con.WorkoutSettings
                     where v.Id == Id
                     select new { v.Header ,v.Title, v.Description, 
                        v.ImageUrl }).First();
            Header.Text = q.Header;
            Title.Text = q.Title;            
            Description.Text = q.Description;
            return q.ImageUrl;
        }
请不要让我知道如何在Linq中使用子字符串,请重新编码我的代码


谢谢

如果
说明
是一个字符串,您可以执行以下操作:

v.Description.Substring(0, 399);

当您将结果分配给
Description.Text
Description.Text=q.Description.Substring(0399)时,也可以在LINQ查询之外执行此操作但仅当
说明
的长度始终大于或等于399个字符时。如果您尝试使用短于399个字符的字符串执行此操作,您将得到一个。解决这个问题的一个方法是:
v.Description.PadRight(399).Substring(0399).Trim()