Exemplo n.º 1
0
 public DatabaseAddin()
 {
     db = new DynamicModel("Database");
     db.PrimaryKeyField = "id";
 }
Exemplo n.º 2
0
 public static DynamicModel Open(string connectionStringName)
 {
     dynamic dm = new DynamicModel(connectionStringName);
     return dm;
 }
Exemplo n.º 3
0
 public SeedDatabaseAddin()
 {
     db = new DynamicModel("Database");
 }
Exemplo n.º 4
0
        public static DynamicModel Open(string connectionStringName)
        {
            dynamic dm = new DynamicModel(connectionStringName);

            return(dm);
        }
Exemplo n.º 5
0
        public dynamic GetOrInsertTable(DynamicModel db, TableDesc tableModel,string keyName, string keyValue)
        {
            var result = db.All(where: string.Format("{0} = @0", keyName), args: new[] { keyValue });
            var count = result.Count();
            if (count == 0)
            {
                IDictionary<string, object> newContent = new ExpandoObject();
                newContent[keyName] = keyValue;
                var fieldValues = (IDictionary<string, object>)tableModel.Values;
                foreach (string fieldName in fieldValues.Keys)
                {
                    newContent[fieldName] = fieldValues[fieldName];
                }

                return db.Insert(newContent);
            }
            else if (count == 1)
            {
                return result.First();
            }
            else
            {
                throw new Exception(string.Format("Multiple content with same name {0}", keyName));
            }
        }