Beispiel #1
0
        public Tuple <Product, Sector> GetProductByIdOnSectorByID(int productId, int sectorId)
        {
            string getSectorProduct = "Select * from sectorProducts";

            getSectorProduct = getSectorProduct + " where product_Id=" + productId.ToString();
            getSectorProduct = getSectorProduct + " and sector_Id=" + sectorId.ToString();

            string getProduct = "Select * from products where Id=";
            string getSector  = "Select * from sectors where Id=";


            using (var con = new SQLiteConnection(_conStr))
            {
                SectorProduct sectorProduct = con.QueryFirstOrDefault <SectorProduct>(getSectorProduct);
                if (sectorProduct == null)
                {
                    return(null);
                }

                getProduct = getProduct + sectorProduct.Product_Id.ToString();
                getSector  = getSector + sectorProduct.Sector_Id.ToString();
                Product product = con.QueryFirst <Product>(getProduct);
                Sector  sector  = con.QueryFirst <Sector>(getSector);
                return(new Tuple <Product, Sector>(product, sector));
            }
        }
Beispiel #2
0
        public Tuple <Product, Sector> GetProductByIdOnSectorByID(int productId, int sectorId)
        {
            using (var ctx = new ProjectDbContext())
            {
                SectorProduct sectorProduct = ctx.sectorProducts.Include(x => x.Product)
                                              .Include(x => x.Sector)
                                              .Where(x => x.Product_Id == productId && x.Sector_Id == sectorId)
                                              .FirstOrDefault();
                if (sectorProduct == null)
                {
                    return(null);
                }

                return(new Tuple <Product, Sector>(sectorProduct.Product, sectorProduct.Sector));
            }
        }