-1

I want to select one field from my database like

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; }
}

but this approach is not working, getting an error System.Linq.Dynamic.ParseException: ''(' expected'.

McNets
  • 10,352
  • 3
  • 32
  • 61
Avinash
  • 107
  • 1
  • 1
  • 7

1 Answers1

0

Try like this:

var selectStatement = "new ( " + DatabaseField + ")";
var filtered = context.MyTable.Select(selectStatement);
Praneet Nadkar
  • 823
  • 7
  • 16
  • already tried, but getting System.NotSupportedException: 'Unable to cast the type 'DynamicClass1' to type 'MyClass'. LINQ to Entities only supports casting EDM primitive or enumeration types – Avinash Mar 22 '18 at 11:38