public ParamInsert ToParamInsert() { var pInsert = ParamInsert.Instance(); pInsert.Insert(GetTableName()); EachColumn(IsUpdate: false, handler: name => pInsert.Column(name, this[name])); return(pInsert); }
public ParamInsert ToParamInsert() { var settings = XElement.Parse(settingXml); var pInsert = ParamInsert.Instance().Insert(getXmlElementValue(settings, "table")); parseColumns(settings, (name, value) => pInsert.Column(name, value)); return(pInsert); }
protected IInsertBuilder BuilderParse(ParamInsert param) { var data = param.GetData(); var insertBuilder = db.Insert(data.From.Length == 0 ? typeof(T).Name : data.From); var dict = GetPersonDateForCreate(); foreach (var column in data.Columns.Where(column => !dict.ContainsKey(column.Key))) { insertBuilder.Column(column.Key, column.Value); } var properties = Zephyr.Utils.ZReflection.GetProperties(typeof(T)); foreach (var item in dict.Where(item => properties.ContainsKey(item.Key.ToLower()))) { insertBuilder.Column(item.Key, item.Value); } return(insertBuilder); }
//protected IInsertBuilder BuilderParse(ParamInsert param) //{ // var data = param.GetData(); // var insertBuilder = db.Insert(data.From.Length == 0 ? typeof(T).Name : data.From); // var dict = GetPersonDateForCreate(); // foreach (var column in data.Columns.Where(column => !dict.ContainsKey(column.Key))) // insertBuilder.Column(column.Key, column.Value); // var properties = Zephyr.Utils.ZReflection.GetProperties(typeof(T)); // foreach (var item in dict.Where(item => properties.ContainsKey(item.Key.ToLower()))) // insertBuilder.Column(item.Key, item.Value); // return insertBuilder; //} /// <summary> /// 拓展和修正该方法 /// </summary> /// <param name="param"></param> /// <returns></returns> protected IInsertBuilder BuilderParse(ParamInsert param) { var data = param.GetData(); var FromTable = data.From.Length == 0 ? typeof(T).Name : data.From.Replace("\r\n", "").Trim(); var insertBuilder = db.Insert(FromTable); var dict = GetPersonDateForCreate(); //获取程序集 反射出程序集下特定Model类 System.Reflection.Assembly t = System.Reflection.Assembly.Load("Zephyr.Web"); Type TypeModel = t.GetType("Zephyr.Models." + FromTable); var properties = Zephyr.Utils.ZReflection.GetProperties(TypeModel);//获取所有属性 //定义实体类上自增标识列集合 List <string> IdentityFieldList = new List <string>(); //取属性上的自定义特性 foreach (var propInfo in properties) { object[] attributes = propInfo.Value.GetCustomAttributes(typeof(IdentityAttribute), false); if (attributes.Length > 0) { IdentityFieldList.Add(propInfo.Key); } } //查询出不包含 CreatePerson,CreateDate,UpdatePerson,UpdateDate 和 不包含 IdentityFieldList自增标识列 的集合 foreach (var column in data.Columns.Where(column => !dict.ContainsKey(column.Key) && !IdentityFieldList.Contains(column.Key))) { insertBuilder.Column(column.Key, column.Value); } //查询出包含 CreatePerson,CreateDate,UpdatePerson,UpdateDate 并给予这些字段赋值 foreach (var item in dict.Where(item => properties.ContainsKey(item.Key))) { insertBuilder.Column(item.Key, item.Value); } return(insertBuilder); }