Ejemplo n.º 1
0
        /// <summary>
        /// در صورت نیاز به ویرایش به صورت غیر متصل و با بهینه سازی خیلی خوب
        /// </summary>
        /// <param name="ctx"></param>
        private static void UpdateDiscountedPerformance(DbContextS04 ctx)
        {
            Customer c = new Customer()
            {
                CustomerId = 1, FName = "ali"
            };

            ctx.Entry(c).Property(x => x.FName).IsModified = true;
            ctx.SaveChanges();
        }
Ejemplo n.º 2
0
        public InvoiceJustKey ExplicitLoading(int id)
        {
            var invoice = ctx.Invoices.First(x => x.InvoiceId == id);

            //load all
            ctx.Entry(invoice).Collection(c => c.InvoiceLines).Load();
            //load with condition
            //ctx.Entry(invoice).Collection(c => c.InvoiceLines).Query().Where(x => x.Price > 100);
            ctx.Entry(invoice).Reference(c => c.Customer).Load();

            return(new InvoiceJustKey
            {
                InvoiceId = invoice.InvoiceId
                , CustomerId = invoice.CustomerId
                , InvoiceLines = invoice.InvoiceLines.Select(l => new InvoiceLineJustKey
                {
                    InvoiceLineId = l.InvoiceLineId
                    , ProductId = l.ProductId
                }).ToList()
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// shadow property
        ///<see langword="see::: " cref="ME.S04.Dal.EF.Customers.CustomerConfiguration"/>
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int CreateBy(int id)
        {
            var customer = ctx.Customers.FirstOrDefault(x => x.CustomerId == id);
            var retval   = ctx.Entry(customer).Property("CreateBy").CurrentValue.ToString();

            //condition on shadow Property
            //ctx.Customers.Where(x => EF.Property<DateTime>(x, "LastUpdated"));

            //for set
            //ctx.Entry(customer).Property("CreateBy").CurrentValue = object;

            return(int.Parse(retval));
        }