Esempio n. 1
0
        public string GetKeyWhere(string where = null)
        {
            if (!string.IsNullOrEmpty(where))
            {
                return(GetWhere(where));
            }

            if (TableInfo != null)
            {
                var field = TableInfo.GetPrimaryKeyField();
                if (field != null)
                {
                    return(" WHERE " + field.DbFieldName + "=@" + field.PropertyName);
                }
            }

            foreach (var property in ModelType.GetProperties())
            {
                if (!DbAttributes.CheckPrimaryKey(property))
                {
                    continue;
                }

                var fieldName = property.Name;
                var attr      = DbAttributes.GetDbFieldInfo(property);
                if (attr != null)
                {
                    fieldName = attr.FieldName;
                }

                return(" WHERE " + fieldName + "=@" + property.Name);
            }

            throw new Exception("can't find primary key when generate delete command!");
        }
Esempio n. 2
0
        public bool CheckPrimaryKey(PropertyInfo property)
        {
            if (TableInfo != null)
            {
                return(TableInfo.CheckPrimaryKey(property.Name));
            }

            return(DbAttributes.CheckPrimaryKey(property));
        }
Esempio n. 3
0
        public void CheckPrimaryKeyTest()
        {
            var type = typeof(AttributeModel);

            var intProperty = type.GetProperties().Where(p => p.Name == "IntProperty").FirstOrDefault();
            var idProperty  = type.GetProperties().Where(p => p.Name == "ID").FirstOrDefault();

            if (intProperty == null || idProperty == null)
            {
                Assert.Fail();
            }

            Assert.IsFalse(DbAttributes.CheckPrimaryKey(intProperty));
            Assert.IsTrue(DbAttributes.CheckPrimaryKey(idProperty));
        }