private Company FindFirstCompany(string company1)
        {
            if (findFirstCompanyQuery == null)
            {
                Expression <Func <ErpContext, string, Company> > expression =
                    (ctx, company1_ex) =>
                    (from row in ctx.Company
                     where row.Company1 == company1_ex
                     select row).FirstOrDefault();
                findFirstCompanyQuery = DBExpressionCompiler.Compile(expression);
            }

            return(findFirstCompanyQuery(this.Db, company1));
        }
        private BankAcct FindFirstBankAcct(string company, string bankAcctID)
        {
            if (findFirstBankAcctQuery == null)
            {
                Expression <Func <ErpContext, string, string, BankAcct> > expression =
                    (ctx, company_ex, bankAcctID_ex) =>
                    (from row in ctx.BankAcct
                     where row.Company == company_ex &&
                     row.BankAcctID == bankAcctID_ex
                     select row).FirstOrDefault();
                findFirstBankAcctQuery = DBExpressionCompiler.Compile(expression);
            }

            return(findFirstBankAcctQuery(this.Db, company, bankAcctID));
        }
        private Currency FindFirstCurrency(string company, string currCode)
        {
            if (findFirstCurrencyQuery2 == null)
            {
                Expression <Func <ErpContext, string, string, Currency> > expression =
                    (ctx, company_ex, CurrCode_ex) =>
                    (from row in ctx.Currency
                     where row.Company == company_ex &&
                     row.CurrencyCode == CurrCode_ex
                     select row).FirstOrDefault();
                findFirstCurrencyQuery2 = DBExpressionCompiler.Compile(expression);
            }

            return(findFirstCurrencyQuery2(this.Db, company, currCode));
        }
        private Currency FindFirstCurrency(string company, bool baseCurr)
        {
            if (findFirstCurrencyQuery == null)
            {
                Expression <Func <ErpContext, string, bool, Currency> > expression =
                    (ctx, company_ex, baseCurr_ex) =>
                    (from row in ctx.Currency
                     where row.Company == company_ex &&
                     row.BaseCurr == baseCurr_ex
                     select row).FirstOrDefault();
                findFirstCurrencyQuery = DBExpressionCompiler.Compile(expression);
            }

            return(findFirstCurrencyQuery(this.Db, company, baseCurr));
        }
        private Country FindFirstCountry3(string company, int countryNum)
        {
            if (findFirstCountry3Query == null)
            {
                Expression <Func <ErpContext, string, int, Country> > expression =
                    (ctx, company_ex, countryNum_ex) =>
                    (from row in ctx.Country
                     where row.Company == company_ex &&
                     row.CountryNum == countryNum_ex
                     select row).FirstOrDefault();
                findFirstCountry3Query = DBExpressionCompiler.Compile(expression);
            }

            return(findFirstCountry3Query(this.Db, company, countryNum));
        }
        private IEnumerable <APTran> SelectAPTran(string company, int headNum)
        {
            if (selectAPTranQuery == null)
            {
                Expression <Func <ErpContext, string, int, IEnumerable <APTran> > > expression =
                    (ctx, company_ex, headNum_ex) =>
                    (from row in ctx.APTran
                     where row.Company == company_ex &&
                     row.HeadNum == headNum_ex
                     orderby row.Company, row.HeadNum, row.APTranNo, row.InvoiceNum
                     select row);
                selectAPTranQuery = DBExpressionCompiler.Compile(expression);
            }

            return(selectAPTranQuery(this.Db, company, headNum));
        }
        private VendBank FindFirstVendBank(string company, int vendorNum, string bankID)
        {
            if (findFirstVendBankQuery == null)
            {
                Expression <Func <ErpContext, string, int, string, VendBank> > expression =
                    (ctx, company_ex, vendorNum_ex, bankID_ex) =>
                    (from row in ctx.VendBank
                     where row.Company == company_ex &&
                     row.VendorNum == vendorNum_ex &&
                     row.BankID == bankID_ex
                     select row).FirstOrDefault();
                findFirstVendBankQuery = DBExpressionCompiler.Compile(expression);
            }

            return(findFirstVendBankQuery(this.Db, company, vendorNum, bankID));
        }