Esempio n. 1
0
        /// <summary>
        /// Using ValueTuple
        /// </summary>
        /// <param name="pCustomerIdentifier"></param>
        /// <returns></returns>
        public (string companyName, bool success) GetCustomerNameByIdentifierUsingEntityFramework_2(int pCustomerIdentifier)
        {
            Customer foundCustomer;

            using (var context = new SimpleEntities())
            {
                foundCustomer = context.Customers.FirstOrDefault(customer => customer.CustomerIdentifier == pCustomerIdentifier);
            }

            return(foundCustomer != null ? (foundCustomer.CompanyName, true) : (foundCustomer.CompanyName, false));
        }
Esempio n. 2
0
        public Customer GetCustomerByIdentifier(int pCustomerIdentifier)
        {
            Customer foundCustomer;

            using (var context = new SimpleEntities())
            {
                foundCustomer = context.Customers
                                .FirstOrDefault(customer => customer.CustomerIdentifier == pCustomerIdentifier);
            }

            return(foundCustomer);
        }
Esempio n. 3
0
 public List <Product> GetAllProducts(bool pIncludeTheKitchenSink)
 {
     using (var context = new SimpleEntities())
     {
         return(pIncludeTheKitchenSink
             ? context.Products
                .Include(prod => prod.Category.Products.Select(product => product.Category))
                .ToList()
             : context.Products
                .Include(prod => prod.Category)
                .ToList());
     }
 }
Esempio n. 4
0
        public string GetCustomerNameByIdentifierUsingEntityFramework_1(int pCustomerIdentifier)
        {
            Customer foundCustomer;

            using (var context = new SimpleEntities())
            {
                foundCustomer = context.Customers.FirstOrDefault(customer => customer.CustomerIdentifier == pCustomerIdentifier);
            }

            if (foundCustomer != null)
            {
                return(foundCustomer.CompanyName);
            }
            else
            {
                return("");
            }
        }