Beispiel #1
0
        private static void FillStatement(ISQLiteStatement statement, BaseEntry obj, bool isUpdate = false)
        {
            var type = obj.GetType();

            var props = type.GetRuntimeProperties()
                        .Where(p => p.CustomAttributes.Count(n => n.AttributeType == typeof(SqlIgnore)) == 0 && NetToSqlKepMap.ContainsKey(p.PropertyType)).ToList();

            for (var i = 0; i < props.Count; i++)
            {
                var sqlProp = props[i].GetCustomAttribute <SqlProperty>();
                if (sqlProp != null && sqlProp.IsPrimaryKey)
                {
                    continue;
                }

                var proptype = props[i].PropertyType;

                //enums need to be cast as long
                object propvalue;

                if (proptype.GetTypeInfo().IsEnum)
                {
                    propvalue = Convert.ToInt64(props[i].GetValue(obj));
                }
                else if (proptype == typeof(DateTime))
                {
                    propvalue = props[i].GetValue(obj).ToString();
                }
                else
                {
                    propvalue = props[i].GetValue(obj);
                }

                statement.Bind(i + 1, propvalue);
            }

            if (isUpdate)
            {
                statement.Bind(props.Count, obj.Id);
            }
        }
Beispiel #2
0
 public static void FillInsert(ISQLiteStatement statement, BaseEntry obj)
 {
     FillStatement(statement, obj);
 }
Beispiel #3
0
 public static void FillUpdate(ISQLiteStatement statement, BaseEntry obj)
 {
     FillStatement(statement, obj, true);
 }