我想从名为“Customer”的表中选择一些行,但是当我使用“db.Customer”定义tableName时似乎错了。我有什么方法可以做到吗?
string tableName = "db.Customer";
var result = from p in tableName
select new
{
ID = p.ID,
Des = p.Description,
type = p.Type,
date = p.DateCreated
};
gridview.DataSource = result;
gridview.DataBind();
答案 0 :(得分:0)
您可以使用CreateQuery方法(接收实体SQL命令)
var result = ctx.CreateQuery<DbDataRecord>(@"select p.ID,
p.Description,
p.Type,
p.DateCreated
from Customer as p");
或ExecuteStoreQuery(执行T-SQL)
var result = ctx.ExecuteStoreQuery<CustomerInfo>(@"select p.ID,
p.Description,
p.Type,
p.DateCreated
from dbo.Customer as p");
public class CustomerInfo
{
public int ID {get; set;}
public string Description {get; set;}
public int Type {get; set;}
public DateTime DateCreated {get; set;}
}