1

I write a Linq-To-Sql syntax is like below:

decimal? sum = UnitOfWork.MorderlistRepository.Select(
    c => c.material_id == Id && c.docstatus_id == 2 && c.is_aborted!=true && c.is_freezed!=true
).Sum(s => s.Qty);

the Select function defined as follow:

public virtual List<BusinessEntityT> Select(Expression<Func<TEFEntity, bool>> expression)
{
    List<BusinessEntityT> bEntities = new List<BusinessEntityT>();
    List<TEFEntity> entities = null;
    entities = _dbSet.Where(expression).ToList();
    foreach (TEFEntity entity in entities)
    {
        BusinessEntityT businessEntity = new BusinessEntityT();
        businessEntity.Context = _db;
        businessEntity.DbInstance = entity;
        bEntities.Add(businessEntity);
    }
    return bEntities;
}

The type of material_id and docstatus_id is int?, is_aborted and is_freezed is bool?.

Now each time when excute to the code

entities = _dbSet.Where(expression).ToList();

I always receive error message

value can't be null,ParamName = 'source'

Why?

MAXE
  • 4,978
  • 2
  • 45
  • 61
user2155362
  • 1,657
  • 5
  • 18
  • 30

1 Answers1

0

You can manage nullable bool easilly in Linq expression usint the null coalescing operator :

x=> (x.myNullableBool ?? false) == false

The same logic an be applied ot int?

x=> (x.myNullableInt ?? -1) == 2
Seb
  • 1,230
  • 11
  • 19