Пример #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());
        }
Пример #2
0
        public string Model2InsertSql(T model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("INSERT INTO ");
            strSql.Append(InnerType.Name);
            strSql.Append("(");

            //strSql.Append("[MemberId],[IdCard],[FullName],[DatInsert] )");
            bool HasStart     = false;
            var  NameUsedList = from u in TypeCache.PropertyNames
                                where !IdentityList.Contains(u) && !UIMemberList.Contains(u)
                                select u;


            foreach (var name in NameUsedList)
            {
                if (TypeCache.IsListProperty(name))
                {
                    continue;
                }

                if (HasStart)
                {
                    strSql.Append(",");
                }
                else
                {
                    HasStart = true;
                }

                strSql.Append("[");
                strSql.Append(name);
                strSql.Append("]");
            }
            strSql.Append(") values (");
            HasStart = false;
            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;
                }

                if (null == PropertyValue)
                {
                    strSql.Append("null");
                }
                else
                {
                    strSql.Append(PropertyValue);
                }
            }

            strSql.Append(")");

            return(strSql.ToString());
        }