Multiple where conditions on entity causes read only property to be true

c# entity-framework-6 telerik-grid


I'm trying to filter the results from an entity, but when I put two where conditions before the load it'll only filter by the first condition like so

      _entity.LineItems.Where(x =>( x.EstID == Est.EstID) && (x.LineItemType == 1)).Load();
      radLaborLineItems.DataSource = _entity.LineItems.Local.ToBindingList();

Also tried it like this with the same results

     _entity.LineItems.Where(x => x.EstID == Est.EstID).Where(y => y.LineItemType == 1).Load();
     radLaborLineItems.DataSource = _entity.LineItems.Local.ToBindingList();

In the above examples since the results are only getting filtered by the first condition I'm able to add new rows, or in other words read only is false. But when I split the conditions out, one on the load and one on the ToBindingList like this...

     _entity.LineItems.Where(x => x.EstID == Est.EstID).Load();
     radLaborLineItems.DataSource = _entity.LineItems.Local.ToBindingList().Where(y => y.LineItemType == 1);

The result is being filtered by both conditions, but I cant add a new row because of a data exception that says collection is read only. I've even tried manually setting the readonly and AllowAddNewRow properties, but still get a readonly error when trying to add a new row.

     radLaborLineItems.ReadOnly = false;
     radLaborLineItems.AllowAddNewRow = true;

So my question is how can I filter an entity by multiple conditions and still have the add new row functionality?

Also worth noting that the results are being bound to a telerik radGridView

4/10/2020 4:57:25 PM

Popular Answer

var lineItemList = (
    from e in _entity.LineItems
        e.EstID == Est.EstID
        && e.LineItemType == 1
    select new LineItemsModel{

// -- Insert -- \\
lineItemList.Add(new LineItemsModel(){
    EstId = 1,
    LineItemType = 2

radLaborLineItems.DataSource = lineItemList;
4/10/2020 5:29:06 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow