Example #1
0
        // Internal
        public void AttachToDBContextInternal(Base obj, Type type, Entity.EntityState state)
        {
            if (obj == null)
            {
                throw new Exception("Cannot add to DB null object");
            }

            if (obj.DBContext != null)
            {
                if (obj.DBContext.Id != Id)
                {
                    throw new Exception("DbContext cannot be changed for object <" + this + "> because another context set already");
                }
                else
                {
                    throw new Exception("Object in context already");
                }
            }
            obj.DBContext = this;

            UUID id = obj.id;

            if (Entities.ContainsKey(id))
            {
                throw new Exception("Cannot add entity <" + obj + "> to DbContext because it already over there");
            }

            Entity entity = new Entity
            {
                Obj   = new WeakReference <Base>(obj),
                Type  = type,
                Order = Entities.Count,
                State = state
            };

            if (state == Entity.EntityState.Added || state == Entity.EntityState.Deleted || state == Entity.EntityState.Modified)
            {
                entity.HardReference = obj;
            }
            Entities.Add(id, entity);
        }
Example #2
0
 // Internal
 public void AttachToDBContextInternal <T>(T obj, Entity.EntityState state) where T : Base => AttachToDBContextInternal(obj, typeof(T), state);