There are two data models:
public class EquipmentProduktModel { public int Id { get; set; } public int EquipmentModelId { get; set; } public virtual EquipmentModel EquipmentModels { get; set; } public int ProduktId { get; set; } public virtual Produkt Produkt { get; set; } public decimal Quantity { get; set; } } public class Produkt { public int Id { get; set; } [Required(ErrorMessage = "Введите названия продукта")] [StringLength(450, MinimumLength = 3, ErrorMessage = "Название должно быть от 1 до 450 символов")] [Display(Name = "Название")] public string Name { get; set; } [Display(Name = "Примечание")] public string Note { get; set; } [Display(Name = "Артикул")] public string Articul { get; set; } [Display(Name = "Штрих код")] public string Barcode { get; set; } [Display(Name = "Единицы измерения")] public virtual Unit Units { get; set; } [Display(Name = "Минимальное количество")] public decimal MinQuantity { get; set; } [Display(Name = "Минимальный заказ")] public decimal MinZakaz { get; set; } public ICollection<EquipmentProduktModel> EquipmentProduktModels { get; set; } [Display(Name = "Учитовать в браке")] public bool BrakOn { get; set; } } How to create a collection of Produkts in which the records already added by EquipmentProduktModel are excluded.
When we form a request:
var List = from p in _context.Produkt from s in _context.EquipmentProduktModel.Where(c=>c.EquipmentModelId == 1012) where p.Id == s.ProduktId select p; That request will create a collection of those records that already exist in EquipmentProduktModel.
But if we change
where p.Id != s.ProduktId That only the first position from the EquipmentProduktModel collection is excluded from the list.
How to create a collection of Produkts correctly excluding those items that have already been made to EquipmentProduktModel.
.Distinct(). - user218976