How get count of an entitySet in Lightswitch

Many people have several problems when work with entitySets in lightswitch. EntitySet are objects that implements IDataServiceQueryable instead IQueryable so it doesnt have access to many linq extension methods.

Two of these are ToList() and Count().

But it implements IExecutable which get us access to Execute() method that return an IEnumerable<> of this EntitySet. The Execute() method executes a query over the EntitySet.

Simply, use the Execute method as below code:

  1. var myCol = DataWorkspace.JoincatalogsData.Categories.Where(m => m.KeyId == “DEFAULT”).Execute();
  2. var myColCount = myCol.Count();

In this case ToList() is not necessary because the Execute() method returns a IEnumerable.

I hope this can help!.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *