Beispiel #1
0
        public string Model2UpdateSql(T model)
        {
            StringBuilder strSql = new StringBuilder();

            // "UPDATE [Class] SET [Sort]=5,[Name]='分类一', WHERE [ClassId]= 1
            strSql.Append("UPDATE [");
            strSql.Append(InnerType.Name);
            strSql.Append("] SET ");
            //strSql.Append("[MemberId],[IdCard],[FullName],[DatInsert] )");
            bool HasStart     = false;
            var  NameUsedList = from u in TypeCache.PropertyNames
                                where u != PrimaryKeyColumn && !UIMemberList.Contains(u)
                                select u;

            HasStart = false;

            #region 循环
            foreach (var name in NameUsedList)
            {
                if (TypeCache.IsListProperty(name))
                {
                    continue;
                }
                var    Property      = TypeCache.PropertyDic[name];
                object PropertyValue = GetProperty2Sql(model, name);
                if (HasStart)
                {
                    strSql.Append(",");
                }
                else
                {
                    HasStart = true;
                }
                strSql.Append("[");
                strSql.Append(name);
                strSql.Append("]=");

                if (null == PropertyValue)
                {
                    strSql.Append("null");
                }
                else
                {
                    strSql.Append(PropertyValue);
                }
            }
            #endregion
            strSql.Append(" WHERE [");
            strSql.Append(PrimaryKeyColumn);

            strSql.Append("] =");
            strSql.Append(GetProperty2Sql(model, PrimaryKeyColumn));

            return(strSql.ToString());
        }