我想从我的数据库中选择一个字段,如
using (MyContext context = new MyContext() )
{
MyClass x = context.MyTable.Where("Id =@0","O1").Select(" new MyClass(DatabaseField)").Cast<MyClass>().Single();
}
public class MyClass
{
public string DatabaseField { get; set; }
}
但这种方法不起作用,收到错误 System.Linq.Dynamic.ParseException:&#39;&#39;(&#39;期待&#39;。
答案 0 :(得分:0)
试试这样:
var selectStatement = "new ( " + DatabaseField + ")";
var filtered = context.MyTable.Select(selectStatement);