private void Set(IDbEntity entity, object value)
        {
            IDbEntity    matchedEntity = DbEntityDataBinder.Eval(EntityPath, entity).Entity;
            PropertyInfo property      = matchedEntity.GetType().GetProperty(PropertyName);

            property.SetValue(matchedEntity, value, null);
        }
        private ICollection <PropertyChange> ChangesForNonDeletedEntities(ISet <string> changePathsPrefixes, long utcTimestamp = long.MaxValue)
        {
            // Get all changes for entities that are not deleted
            List <PropertyChange> dbEntityChanges = new List <PropertyChange>(
                _changes
                .Where(c => c.UtcTimestamp <= utcTimestamp)
                .Where(c => !c.IsOrphan(_entity))
                .Where(c =>
            {
                bool returnChange = false;
                if (!string.IsNullOrEmpty(c.EntityPath))
                {
                    bool startsWithPathPrefix = changePathsPrefixes.Any(p => c.EntityPath.StartsWith(p));
                    IDbEntity entity          = DbEntityDataBinder.Eval(c.EntityPath, _entity).Entity;
                    returnChange = startsWithPathPrefix && (!(entity as IDbEntityBasic).IsDeleted || entity.State == EntityState.Persisted);
                }
                return(returnChange);
            }));

            // Get all flat property changes
            dbEntityChanges.AddRange(
                _changes
                .Where(c => string.IsNullOrEmpty(c.EntityPath)));

            return(dbEntityChanges);
        }
Esempio n. 3
0
        public void Eval_one_degree_separation_collection_one_degree_separation_entity_property_indexers_return_entity()
        {
            int entity1Id = 1;
            int entity2Id = 2;
            MockAssociativeEntity associativeEntity = new MockAssociativeEntity()
            {
                RelationalEntity1Id = entity1Id, RelationalEntity2Id = entity2Id, RelationalEntity2 = new MockEntity()
                {
                    id = entity2Id
                }
            };
            MockEntity entity = new MockEntity()
            {
                id = entity1Id, AssociativeEntities = new HashSet <MockAssociativeEntity>()
                {
                    associativeEntity
                }
            };
            string path = ".AssociativeEntities[Guid=" + associativeEntity.Guid + ",RelationalEntity1Id=" + entity1Id + ",RelationalEntity2Id=" + entity2Id + "].RelationalEntity2";

            DbEntityDataBinder.BinderResult result = DbEntityDataBinder.Eval(path, entity);

            Assert.AreEqual(associativeEntity.RelationalEntity2, result.Entity);
            Assert.AreEqual(path, result.Path);
            Assert.AreEqual(".AssociativeEntities[RelationalEntity1Id=" + entity1Id + ",RelationalEntity2Id=" + entity2Id + "].RelationalEntity2", result.ActualPath);
        }
Esempio n. 4
0
        public void Eval_root_path_return_root_entity()
        {
            MockEntity entity = new MockEntity();
            string     path   = ".";

            DbEntityDataBinder.BinderResult result = DbEntityDataBinder.Eval(path, entity);

            Assert.AreEqual(entity, result.Entity);
            Assert.AreEqual(path, result.Path);
            Assert.AreEqual(path, result.ActualPath);
        }
Esempio n. 5
0
        public void Eval_null_entity_return_null()
        {
            MockEntity entity = new MockEntity();
            string     path   = ".RelationalEntity1";

            DbEntityDataBinder.BinderResult result = DbEntityDataBinder.Eval(path, entity);

            Assert.IsNull(result.Entity);
            Assert.AreEqual(path, result.Path);
            Assert.AreEqual(path, result.ActualPath);
        }
Esempio n. 6
0
        public void Eval_one_degree_separation_relation_return_entity()
        {
            MockEntity relationalEntity = new MockEntity();
            MockEntity entity           = new MockEntity()
            {
                RelationalEntity1 = relationalEntity
            };
            string path = ".RelationalEntity1";

            DbEntityDataBinder.BinderResult result = DbEntityDataBinder.Eval(path, entity);

            Assert.AreEqual(relationalEntity, result.Entity);
            Assert.AreEqual(path, result.Path);
            Assert.AreEqual(path, result.ActualPath);
        }
        public bool IsDeleted(string entityPath, out IDbEntity e)
        {
            string[] split = entityPath.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            e = _entity;
            bool   isDeleted = (_entity as IDbEntityBasic).IsDeleted;
            string path      = string.Empty;

            for (int i = 0; i < split.Length && !isDeleted; i++)
            {
                path += "." + split[i];
                IDbEntity entity = DbEntityDataBinder.Eval(path, _entity).Entity;
                if (entity != null)
                {
                    e         = entity;
                    isDeleted = (entity as IDbEntityBasic).IsDeleted;
                }
            }

            return(isDeleted);
        }
        public bool IsOrphan(IDbEntity entity)
        {
            IDbEntity matchedEntity = DbEntityDataBinder.Eval(EntityPath, entity).Entity;

            return(matchedEntity == null || !matchedEntity.Guid.Equals(EntityGuid));
        }