Make queries with else in entity framework linq RRS feed

  • Question

  • Hello

    Afternoon lords programmers if someone guides me please I'm doing a product sale application I have a part where I should look for bulk products I have a bar code that does the search

    My problem is generated when I have to sell products in bulk
    My table products

    IdProduct, barcorde, name Product price Idmedida IdSubFamilia

    Then wanted to make a query that brings the products with the barcorde and idmedida = 3 (this is kilogram)

    And if the idmeasure is other than 3

    Ask me the other query

    This query that works alone

    It's in text box


    Private void Txtbarcorde_KeyPress (object sender, KeyPressEventArgs e)
                If (TxtCodigoBarras.Text.Length> 0)
                    If (e.KeyChar == Convert.ToChar (Keys.Return))
                        DetailDentaDTO eDeta = new DetailDentaDTO ();
                        PRODUCT eProd = new PRODUCT ();
                        EProd = objProducto.GetBybarcorde (Txtbarcorde.Text);
                        // eProd = objProducto.GetByCodigoBarras (Txtbarcorde.Text);
                        If (eProd == null)
                            If (MessageBoxButton.Show ("Product does not exist, Do you want to add it?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                                Form frm = this.MdiChildren.FirstOrDefault (x => x is FrmProducts);
                                If (frm! = Null)
                                    Frm.BringToFront ();
                                Frm = new FrmProductos (idUsuario);
                                Frm.MdiParent = this.MdiParent;
                                Frm.Show ();
                        If (eProd.Stock <= 0)
                            MessageBox.Show ("Not enough stock to sell", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        EDeta.Quantity = 1;
                        EDeta.barcorde = eProd.barcorde;
                        EDeta.FeedReg = DateTime.Now;
                        EDeta.IdDetalle = 0;
                        EDeta.IdProduct = eProd.IdProduct;
                        EDeta.IdVenta = 0;
                        EDeta.Import = eProd.Price * eDeta.Quantity;
                        EDeta.ProductName = ProductProductName;
                        EDeta.PorcentageIVA = Imposed. Tax rate;
                        EDeta.Price = eProd.Price;
                        Details.Add (eDeta);
                        //DgvDetalle.DataSource = null;
                        DgvDetalle.DataSource = Details;
                        Txtbarcorde.Clear ();
                        Txtbarcorde.Focus ();

    Wednesday, May 3, 2017 12:04 AM

All replies

  • Hi djnilo,

    According to your description, I am not sure what is your requirement, Could you please describe in detail.

    If you want to search a result via LINQ, please refer to the following code.

    using (var db = new AdoNetEntities())
       List<product> query = db.products.Where(t => t.barcorde == "youbarcodevalue" && t.Idmedida == 3).ToList();

    Best regards,

    Cole Wu

    MSDN Community Support&lt;br/&gt; Please remember to click &amp;quot;Mark as Answer&amp;quot; the responses that resolved your issue, and to click &amp;quot;Unmark as Answer&amp;quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact &lt;a href=&quot;;&gt;;/a&gt;.

    Wednesday, May 3, 2017 7:34 AM