示例#1
0
        public void UpdateSingleField <TEntity, TProp>(Expression <Func <TEntity, TProp> > expression, Action <TEntity> setUnique, TProp value)
            where TEntity : class, new()
        {
            var entity = new TEntity();

            setUnique(entity);

            var memberSelectorExpression = expression.Body as MemberExpression;
            var property = memberSelectorExpression.Member as PropertyInfo;

            property.SetValue(entity, value, null);


            _entities.Set <TEntity>().Attach(entity);
            _entities.Entry(entity).Property(expression).IsModified = true;
        }
        public void BasicPreload()
        {
            var context = new SociatisEntities();

            var set = context.Set <Region>();

            var basicInformations =
                context.Regions
                .Select(r => new { RegionID = r.ID, CountryID = r.CountryID, Developement = r.Development })
                .ToList();

            foreach (var info in basicInformations)
            {
                var region = storage.First(r => r.ID == info.RegionID);
                region.CountryID   = info.CountryID;
                region.Development = info.Developement;
            }
        }
        public void Init()
        {
            storage.Clear();

            var context = new SociatisEntities();

            var entities = context.Set <TEntity>().ToList();

            foreach (var entity in entities)
            {
                var persistentEntity = new TEntity();

                PreLoadEntity(persistentEntity, entity);
                CleanNavigationalProperties(persistentEntity);
                LoadEntity(persistentEntity, entity);

                storage.Add(persistentEntity);
            }

            AfterLoad();
        }