Пример #1
0
        protected void CreateDb()
        {
            string appDbCollection = "asciichars";

            var ss     = new SeriousSerializer();
            var appCfg = ss.BinaryDeserializer <ApplicationCfg>(configurationPath);

            appCfg.DatabasePath    = databasePath;
            appCfg.AppDbCollection = appDbCollection;

            ss.BinarySerializer(appCfg, configurationPath);

            var entities = new List <BaseDbModel>();

            for (int i = 0; i < 127; i++)
            {
                var entity = new BaseDbModel
                {
                    Character = (char)i
                };
                entities.Add(entity);
            }
            using (var db = new LiteDatabase(databasePath))
            {
                var collection = db.GetCollection <BaseDbModel>("asciichars");
                collection.InsertBulk(entities);
            }

            ProceedWith(DefineTargetString);
        }
Пример #2
0
        public DataConflictException(string errorType, DataConflictInfo info)
            : base(errorType, "Data conflict (Optimistic concurrency)")
        {
            BaseDbModel dbValues = (BaseDbModel)info.DatabaseValues.ToObject();
            BaseDbModel cValues  = (BaseDbModel)info.CurrentValues.ToObject();

            this.DatabaseValues = dbValues;
            this.CurrentValues  = cValues;
        }
        private void SetCreatedAndModified(BaseDbModel entity, EntityState state, int userId)
        {
            if (entity != null)
            {
                var now = DateTime.UtcNow;

                if (state == EntityState.Added)
                {
                    entity.CreatedById = userId; //?? "unknown";
                    entity.CreatedDate = now;
                }
                entity.ModifiedById = userId;// ?? 0;
                entity.ModifiedDate = now;
            }
        }
Пример #4
0
 public static int GetSqlParamValue(this BaseDbModel value)
 {
     return(value == null ? 0 : value.Id);
 }
Пример #5
0
 public static bool IsEmptyValue(this BaseDbModel value)
 {
     return(value == null || value.Id == 0);
 }