Exemplo 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!");
        }
Exemplo n.º 2
0
        public void GetDbFieldInfoTest()
        {
            var type = typeof(AttributeModel);

            var property = type.GetProperties().Where(p => p.Name == "IntProperty").FirstOrDefault();

            if (property == null)
            {
                Assert.Fail();
            }
            var attr = DbAttributes.GetDbFieldInfo(property);

            if (attr == null)
            {
                Assert.Fail();
            }
            Assert.AreEqual("IntField", attr.FieldName);
        }