protected void InitSortingMaterials() { if (LabelMaterialData.Text == "") { // get the current freight Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext); // enumerate all materials for this collection string Query = "select value it from MaterialSet as it where it.IsActive and (not it.IsWorkInsteadOfMaterial) and it.Location.Id = @LocationId and ((it.InvoiceType = @InvoiceType) or (it.InvoiceType = \"Both\")) order by it.Description"; ObjectQuery <Material> query = new ObjectQuery <Material>(Query, ControlObjectContext).Include("Location"); query.Parameters.Add(new ObjectParameter("LocationId", new Guid(ComboBoxWeighingLocation.SelectedValue))); query.Parameters.Add(new ObjectParameter("InvoiceType", LabelMaterialInvoiceType.Text)); ObjectResult <Material> MaterialList = query.Execute(MergeOption.AppendOnly); foreach (Material Mat in MaterialList) { FreightSortingMaterial fsm = new FreightSortingMaterial(); fsm.Material = Mat; if (frg != null) { FreightSortingMaterial existing_fsm = frg.CheckForSortingMaterial(Mat, ControlObjectContext); if (existing_fsm != null) { fsm = existing_fsm; } } fsm.Description = Mat.Description; MaterialLines.Add(fsm); } SaveSortingMaterials(); } }