在实体框架linq中使用else进行查询 [英] Make queries with else in entity framework linq

查看:79
本文介绍了在实体框架linq中使用else进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好b


下午领主程序员,如果有人指导我请我做产品销售申请我有一个部分,我应该寻找散装产品我有一个用于搜索的条形码。


当我必须批量销售产品时,我的问题就产生了。
我的餐桌产品



IdProduct,barcorde,name产品价格Idmedida IdSubFamilia



然后想做一个带有产品的查询barcorde和idmedida = 3(这是千克)



b
b $ b b b如果idmeasure不是3



向我询问其他询问



$


这个查询单独使用





它在文本框中为






条形码

 Private void Txtbarcorde_KeyPress(object sender,KeyPressEventArgs e)
         {
             if(TxtCodigoBarras.Text.Length> 0)
             {
       &NBSP ;        如果(e.KeyChar == Convert.ToChar(Keys.Return))
      &NBSP ;          {
                      DetailDentaDTO eDeta = new DetailDentaDTO();
                    产品eProd =新产品( );
                     EProd = objProducto.GetBybarcorde( Txtbarcorde.Text);
                     // eProd = objProducto。 GetByCodigoBarras(Txtbarcorde.Text);
                    如果(eProd == NULL )
                     {
                      If( MessageBoxButton.Show("产品不存在,是否要添加它?","确认",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button2)== DialogResult.Yes)
                          {
                        &NBSP ;    Form frm = this.MdiChildren.FirstOrDefaul t(x => x是FrmProducts);
                             如果(FRM!= NULL)
              &NBSP ;              {
          ,                    Frm.BringToFront( );
                                 返回;
                             }
                 &NBSP ;           Frm = new FrmProductos(idUsuario);
                              Frm.MdiParent = this.MdiParent;
                              Frm.Show();
                         }
                     &NBSP ;  返回;
                    }
&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(eProd.Stock< = 0)
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {
&NBSP; ,                    MessageBox.Show( "没有足够的股票卖出","警告",MessageBoxButtons.OK,MessageBoxIcon.Error);
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;返回;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}


                     EDeta.Quantity = 1;



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;     EDeta.barcorde = eProd.barcorde;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; EDETA。 FeedReg = DateTime.Now;
                     EDeta.IdDetalle = 0;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; EDeta.IdProduct = eProd。 IdProduct;
                     EDeta.IdVenta = 0;
                     EDeta.Import = eProd。价格* eDeta.Quantity;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; EDeta.ProductName = ProductProductName;
                     EDeta.PorcentageIVA = Imposed。税率;
                     EDeta.Price = eProd。价钱;
                     Details.Add(eDeta) ;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; // DgvDetalle.DataSource =空值;
                     DgvDetalle.DataSource = Details;
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Txtbarcorde.Clear();
                     Txtbarcorde.Focus();
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;       }
        }




解决方案

您好djnilo,


根据您的描述,我不确定您的要求是什么,请您详细说明。


如果您想通过LINQ搜索结果,请参考以下代码。

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

祝你好运,


Cole Wu


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



Barcode

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 ();
                                Return;
                            }
                            Frm = new FrmProductos (idUsuario);
                            Frm.MdiParent = this.MdiParent;
                            Frm.Show ();
                        }
                        Return;
                    }
                    If (eProd.Stock <= 0)
                    {
                        MessageBox.Show ("Not enough stock to sell", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Return;
                    }


                    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 ();
                }
            }
        }


解决方案

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


这篇关于在实体框架linq中使用else进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆