我想生成一个类似于 sql select 的 select 语句:
public partial class Person{
public string Name {get;set;}
public string FirstName{ get;set;}
public string DisplayName {get;set;}
public string Town{get;set;}
public int Age {get;set;}
}
select p.*, (p.NAME + ', ' + p.FirstName) as DisplayName from Person p
在 linq 我会这样做
from p in Person select new
{
p.Name, p.FirstName, p.Age, p.Town, // and so on...
DisplayName = p.NAME + ', ' + p.FirstName
}
有没有办法在不列出每个属性的情况下在 sql select 中做到这一点?
更新 :
因为我在这里使用 linqToDB 原始类:
[Table("PERSON")]
public class Person{
[Column("ID"), PrimaryKey, NotNull]
public int Id { get; set; }
[Column("NAME")]
public string Name {get;set;}
[Column("FIRST_NAME")]
public string FirstName{ get;set;}
public string DisplayName {get;set;}
[Column("TOWN")]
public string Town{get;set;}
[Column("AGE")]
public int Age {get;set;}
}