public void MapperModel() { var config = new MapperConfiguration(cfg => cfg.AddProfile<OrganizationProfile>()); //var goods = new Goods() //{ // GoodId = 10 //}; var mapper = config.CreateMapper(); var goods = new ShopContext().Goods.Where(g => g.GoodId < 10); var dest = goods.ProjectTo<DestGood>(config); CollectionAssert.Contains(dest.Select(d=>d.goodId),Enumerable.Range(1,9)); }
public void EfEdit() { var context = new ShopContext(); // context.Configuration.AutoDetectChangesEnabled = false; var colorEdit = context.Colors.Find(8); colorEdit.ColorNameEn = "sky blue 1000"; colorEdit.ColorNameRu = "Светло синий - 10"; context.Entry(colorEdit).Property(c=>c.ColorNameRu).IsModified = true; context.SaveChanges(); }
public void EfAttach() { var context = new ShopContext(); var color = new Color(); color.ColorNameEn = "sky blue"; color.ColorNameRu = "Светло синий"; var colorAdded = context.Entry(color); colorAdded.State = EntityState.Added; context.SaveChanges(); }
public void RealDataColor() { var context = new ShopContext(); var param = Expression.Parameter(typeof(Color)); var prop = Expression.Property(param, typeof(Color), "ColorId"); var body = Expression.GreaterThan(prop, Expression.Constant(5)); Expression<Func<Color, bool>> expR = Expression.Lambda<Func<Color, bool>>(body, param); //expR.Dump(); //var param1 = Expression.Parameter(typeof (Color)); var prop1 = Expression.Property(param, typeof(Color), "ColorId"); var body1 = Expression.GreaterThan(prop1, Expression.Constant(5)); var inv = Expression.Lambda<Func<Color, bool>>(body1, param); //inv.Dump(); var exprL = Expression.Invoke(inv, param); var all = Expression.AndAlso(expR.Body, exprL); var and = Expression.Lambda<Func<Color, bool>>(all, param); var func = and.ReduceExtensions(); Expression<Func<Color, bool>> e = (d) => d.ColorId > 5; var data = context.Colors.AsQueryable().Where(and.Compile()).AsQueryable(); Assert.That(data.Count(), Is.EqualTo(7)); }
public UnitOfWorkStore(ShopContext context) { _context = context; }