/// <summary> /// 初始化跟Reader的映射信息 /// </summary> /// <param name="reader"></param> public void InitReaderMapping(IDataReader reader) { _lstReaderMapping = new List <AliasReaderMapping>(_dicPropertyInfo.Count); int fCount = reader.FieldCount; EntityPropertyInfo info = null; for (int i = 0; i < fCount; i++) { string colName = reader.GetName(i); if (_dicPropertyInfo.TryGetValue(colName, out info)) { AliasReaderMapping aliasMapping = new AliasReaderMapping(i, info, !info.TypeEqual(reader, i)); if (aliasMapping != null) { _lstReaderMapping.Add(aliasMapping); if (info.IsPrimaryKey) { _primaryMapping = aliasMapping; } } } } foreach (KeyValuePair <string, AliasTableMapping> keyPair in _dicChildTables) { keyPair.Value.InitReaderMapping(reader); } //_baseList = new ArrayList(); }
protected override Expression VisitMethodCall(MethodCallExpression methodCall) { if (methodCall.Method.MetadataToken == GetMethod.MetadataToken && Equals(methodCall.Method.Module, GetMethod.Module)) { object value; Throw <ODataCompileException> .If( !LinqHelpers.TryGetValue(methodCall.Arguments[0], LinqHelpers.GetValueOptions.All, out value), () => string.Format( "Unable to extract value for parameter '{0}' of {1}. Ensure that the value for the parameter can be statically determined", methodCall.Method.GetParameters()[0].Name, methodCall.Method ) ); var propertyName = (string)value; Throw <ODataCompileException> .If( string.IsNullOrWhiteSpace(propertyName), () => string.Format( "'{0}' value for {1} must not be null or whitespace", methodCall.Method.GetParameters()[0].Name, methodCall.Method ) ); var property = EntityPropertyInfo.For(name: propertyName, type: methodCall.Method.GetGenericArguments()[0]); return(Expression.Property(this.Visit(methodCall.Object), property)); } return(base.VisitMethodCall(methodCall)); }
private static String getInsertSql(EntityInfo entityInfo) { String str = "insert into " + entityInfo.TableName + " ("; String fStr = ""; String vStr = ") values("; for (int i = 0; i < entityInfo.SavedPropertyList.Count; i++) { EntityPropertyInfo info = entityInfo.SavedPropertyList[i]; if (( (/**/ !DbConfig.Instance.IsAutoId || !(info.Name.ToLower() == "id") || (entityInfo.Parent != null)) && info.SaveToDB) && (!info.IsList && !info.IsList) ) { String col = info.ColumnName ?? ""; fStr = fStr + col + ", "; vStr = vStr + entityInfo.Dialect.GetParameter(info.ColumnName) + ", "; } } fStr = fStr.Trim().TrimEnd(','); vStr = vStr.Trim().TrimEnd(','); str = str + fStr + vStr + ")"; logger.Info(LoggerUtil.SqlPrefix + entityInfo.Name + " InsertSql:" + str); return(str); }
//------------------------------------- 以下实例方法 -------------------------------------------- /// <summary> /// 根据属性名称获取属性的值 /// </summary> /// <param name="propertyName">属性名称</param> /// <returns></returns> public Object get(String propertyName) { EntityInfo ei = getEntityInfo(); if (propertyName.IndexOf(".") < 0) { EntityPropertyInfo ep = ei.GetProperty(propertyName); if (ep == null) { return(null); } return(ep.GetValue(this)); } String[] arrItems = propertyName.Split(new char[] { '.' }); Object result = null; ObjectBase <T> obj = this; for (int i = 0; i < arrItems.Length; i++) { if (i < (arrItems.Length - 1)) { obj = (ObjectBase <T>)obj.get(arrItems[i]); } else { result = obj.get(arrItems[i]); } } return(result); }
private object GetDefaultConcurrency( EntityPropertyInfo info) { DbType type = info.SqlType; if (type == DbType.DateTime || type == DbType.Time || type == DbType.Date) { return(DateTime.Now); } else if (type == DbType.Int64 || type == DbType.Decimal || type == DbType.Double || type == DbType.Int32 || type == DbType.Int16 || type == DbType.Double || type == DbType.SByte || type == DbType.Byte || type == DbType.Currency || type == DbType.UInt16 || type == DbType.UInt32 || type == DbType.UInt64 || type == DbType.VarNumeric ) { return(1); } else if (type == DbType.String) { return(CommonMethods.GuidToString(Guid.NewGuid())); } else if (type == DbType.Guid) { return(Guid.NewGuid()); } return(null); }
private static bool shouldPass(EntityPropertyInfo info) { if (info.Type == typeof(int)) { return(false); } if (info.Type == typeof(string)) { return(false); } if (info.Type == typeof(decimal)) { return(false); } if (info.Type == typeof(DateTime)) { return(false); } if (info.Type == typeof(bool)) { return(false); } if (info.Type == typeof(double)) { return(false); } if (info.IsEntity) { return(false); } return(true); }
private void addColumnSingle(EntityInfo entity, StringBuilder sb, EntityPropertyInfo ep, String columnName) { if (ep.Type == typeof(int)) { addColumn_Int(sb, ep, columnName); } else if (ep.Type == typeof(long)) { addColumn_Long(sb, columnName); } else if (ep.Type == typeof(DateTime)) { addColumn_Time(sb, columnName); } else if (ep.Type == typeof(decimal)) { addColumn_Decimal(entity, sb, ep, columnName); } else if (ep.Type == typeof(double)) { addColumn_Double(entity, sb, columnName); } else if (ep.Type == typeof(float)) { addColumn_Single(entity, sb, columnName); } else if (ep.Type == typeof(String)) { addColumn_String(entity, sb, ep, columnName); } else if (ep.IsEntity) { addColumn_entity(sb, columnName); } }
private void setObjectProperties(EntityInfo entityInfo, Type t, Object obj) { String camelType = strUtil.GetCamelCase(t.Name); String prefix = camelType + "."; NameValueCollection posts = _context.postValueAll(); foreach (String key in posts.Keys) { if (key.StartsWith(prefix) == false) { continue; } String propertyName = strUtil.TrimStart(key, prefix); PropertyInfo p = t.GetProperty(propertyName); if (p == null) { continue; } if (entityInfo == null) { setPropertyValue(obj, p, posts[key]); } else { EntityPropertyInfo ep = entityInfo.GetProperty(propertyName); setEntityPropertyValue(obj, ep, posts[key]); } } }
private void setEntityPropertyValue(Object obj, EntityPropertyInfo p, String postValue) { if (p.Type == typeof(int)) { p.SetValue(obj, cvt.ToInt(postValue)); } else if (p.Type == typeof(String)) { p.SetValue(obj, getAutoPostString(p.Property, postValue)); } else if (p.Type == typeof(Decimal)) { p.SetValue(obj, cvt.ToDecimal(postValue)); } else if (p.Type == typeof(Double)) { p.SetValue(obj, cvt.ToDouble(postValue)); } else if (p.Type == typeof(DateTime)) { p.SetValue(obj, cvt.ToTime(postValue)); } else if (p.IsEntity) { IEntity objProperty = Entity.New(p.EntityInfo.FullName); objProperty.Id = cvt.ToInt(postValue); p.SetValue(obj, objProperty); } }
public static String GetSameTypeIds(Type throughType, Type t, int id) { // 1029 ObjectInfo state = new ObjectInfo(throughType); String relationPropertyName = state.EntityInfo.GetRelationPropertyName(t); EntityPropertyInfo info = state.EntityInfo.FindRelationProperty(t); String ids = ObjectDB.Find(state, relationPropertyName + ".Id=" + id).get(info.Name + ".Id"); EntityPropertyInfo property = state.EntityInfo.GetProperty(relationPropertyName); String sql = String.Format("select distinct {0} from {1} where {2} in ({3}) and {0}<>{4}", property.ColumnName, state.EntityInfo.TableName, info.ColumnName, ids, id); IDbCommand command = DataFactory.GetCommand(sql, DbContext.getConnection(state.EntityInfo)); IDataReader rd = null; StringBuilder builder = new StringBuilder(); try { rd = command.ExecuteReader(); while (rd.Read()) { builder.Append(rd[0]); builder.Append(","); } } catch (Exception exception) { logger.Error(exception.Message); throw new OrmException(exception.Message, exception); } finally { OrmHelper.CloseDataReader(rd); } return(builder.ToString().TrimEnd(',')); }
private string getEntityPropertyName(EntityPropertyInfo ep, object propertyValue) { IEntity pValue = propertyValue as IEntity; if (pValue == null) { return(""); } string val = null; EntityInfo ei = Entity.GetInfo(pValue); if ((ei.GetProperty("Name") != null) && (pValue.get("Name") != null)) { val = pValue.get("Name").ToString(); } else if ((ei.GetProperty("Title") != null) && (pValue.get("Title") != null)) { val = pValue.get("Title").ToString(); } if (strUtil.HasText(val)) { String lnk = to(Model) + "?typeName=" + ep.ParentEntityInfo.FullName + "&p=" + ep.Name + "&id=" + pValue.Id; return("<a title=\"" + ep.Type.FullName + ", Id=" + pValue.Id + "\" href=\"" + lnk + "\">" + val + "</a>"); } else { return(ep.Type.Name + "_" + pValue.Id); } }
/// <summary> /// 创建Reader缓存 /// </summary> internal static List <EntityPropertyInfo> GenerateCache(IDataReader reader, EntityInfoHandle entityInfo) { IDBAdapter idb = entityInfo.DBInfo.CurrentDbAdapter; Dictionary <string, EntityPropertyInfo> dicParamHandle = new Dictionary <string, EntityPropertyInfo>();//获取字段名跟属性对照的集合 //Dictionary<string, EntityPropertyInfo>.Enumerator enums = entityInfo.PropertyInfo.GetPropertyEnumerator(); foreach (EntityPropertyInfo info in entityInfo.PropertyInfo) { //EntityPropertyInfo info=enums.Current.Value; dicParamHandle.Add(info.ParamName, info); dicParamHandle[idb.FormatParam(info.ParamName)] = info; } List <EntityPropertyInfo> cacheReader = new List <EntityPropertyInfo>(); for (int i = 0; i < reader.FieldCount; i++) //把属性按照指定字段名顺序排列到List里边 { EntityPropertyInfo info = null; if (dicParamHandle.TryGetValue(reader.GetName(i), out info))//获取数据库字段名对应的实体字段反射 { cacheReader.Add(info); } else { cacheReader.Add(null); } } return(cacheReader); //dicReaderCache.Add(type.FullName,cacheReader); }
/// <summary> /// 填充该列表的子类 /// </summary> /// <param name="sender">发送者</param> public static void FillParent(string propertyName, EntityBase sender) { if (sender.HasPropertyChange(propertyName)) { return; } Type senderType = CH.GetRealType(sender); //发送者类型 EntityInfoHandle senderInfo = EntityInfoManager.GetEntityHandle(senderType); //获取发送类的信息 EntityMappingInfo mappingInfo = senderInfo.MappingInfo[propertyName]; //if (mappingInfo.GetValue(sender) != null) //{ // return; //} //IList baseList = sender.GetBaseList();//获取上一次查询的结果集合 //if (baseList == null) //{ // baseList = new ArrayList(); // baseList.Add(sender); //} //Dictionary<string, ArrayList> dicElement = new Dictionary<string, ArrayList>(); if (mappingInfo != null) { EntityPropertyInfo senderHandle = mappingInfo.SourceProperty;//本类的主键属性句柄 //IList pks = CollectFks(baseList, senderHandle, mappingInfo, dicElement, senderInfo.DBInfo); EntityInfoHandle fatherInfo = mappingInfo.TargetProperty.BelongInfo; object pk = senderHandle.GetValue(sender); FillParent(pk, fatherInfo, mappingInfo, propertyName, sender); } }
/// <summary> /// 获取自动增长值的SQL /// </summary> /// <returns></returns> public string GetIdentityValueSQL(EntityPropertyInfo pkInfo) { if (pkInfo == null) { throw new Exception("找不到主键属性"); } return("select \"" + GetSequenceName(pkInfo) + "\".nextval as curVal from dual"); }
//private static Dictionary<string, bool> dicSequence = new Dictionary<string, bool>();//序列已经初始化的集合 /// <summary> /// 获取该属性的序列 /// </summary> /// <param name="info"></param> /// <returns></returns> public static string GetSequenceName(EntityPropertyInfo info) { if (!string.IsNullOrEmpty(info.ParamInfo.SequenceName)) { return(info.ParamInfo.SequenceName); } return(GetDefaultName(info.BelongInfo.TableName, info.ParamInfo.ParamName)); }
internal static PropertyInfo GetProperty(string name, Type type) { #if !NETCORE return(EntityPropertyInfo.For(name, type)); #else throw ODataEntityQueriesNotSupported(); #endif }
/// <summary> /// 获取自动增长的SQL /// </summary> /// <returns></returns> public string GetIdentitySQL(EntityPropertyInfo info) { if (info == null) { throw new Exception("找不到自增属性"); } return("select currval('\"" + GetSequenceName(info) + "\"')"); }
/// <summary> /// 获取自动增长值的SQL /// </summary> /// <returns></returns> public string GetIdentityValueSQL(EntityPropertyInfo info) { //if (info == null) //{ // throw new Exception("找不到主键属性"); //} //return "PREVIOUS VALUE FOR \"" + GetSequenceName(info.BelongInfo.TableName, info.ParamName) + "\""; return(null); }
/// <summary> /// 获取自动增长的SQL /// </summary> /// <returns></returns> public string GetIdentitySQL(EntityPropertyInfo info) { //if (info == null) //{ // throw new Exception("找不到主键属性"); //} //return "select LASTASSIGNEDVAL from SYSIBM.SYSSEQUENCES where SEQNAME='" + GetSequenceName(info.BelongInfo.TableName, info.ParamName) + "'"; return("VALUES IDENTITY_VAL_LOCAL()"); }
private string getPropertyValue(IEntity obj, EntityPropertyInfo ep) { object val = obj.get(ep.Name); if (val == null) { return(""); } return(val.ToString()); }
/// <summary> /// 收集外键值 /// </summary> /// <param name="lst"></param> /// <param name="pk"></param> /// <returns></returns> private static Queue <object> CollectFks(IEnumerable lst, EntityPropertyInfo pk) { Queue <object> pks = new Queue <object>(); foreach (object obj in lst) { object value = pk.GetValue(obj); pks.Enqueue(value); } return(pks); }
/// <summary> /// 1.5新增,针对已删除用户应用 null object 模式 /// </summary> /// <param name="obj"></param> /// <param name="ep"></param> /// <param name="propertyValue"></param> public static void setEntityByCheckNull( IEntity obj, EntityPropertyInfo ep, Object propertyValue, int realUserId ) { if (propertyValue == null && rft.IsInterface( ep.Type, typeof( IUser ) )) { IEntity user = getNullUser( realUserId ); obj.set( ep.Name, user ); } else { obj.set( ep.Name, propertyValue ); } }
public static IList FindDataOther(Type throughType, Type t, String order, int id) { // 1029 ObjectInfo state = new ObjectInfo(throughType); String relationPropertyName = state.EntityInfo.GetRelationPropertyName(t); EntityPropertyInfo info = state.EntityInfo.FindRelationProperty(t); state.Order = order; state.include(info.Name); return(ObjectDB.Find(state, relationPropertyName + ".Id=" + id).listChildren(info.Name)); }
private void addColumns(EntityInfo entity, StringBuilder sb) { for (int i = 0; i < entity.SavedPropertyList.Count; i++) { EntityPropertyInfo ep = entity.SavedPropertyList[i]; String columnName = getFullName(ep.ColumnName, entity); if ((ep.SaveToDB && !ep.IsList) && !(ep.Name == "Id")) { addColumnSingle(entity, sb, ep, columnName); } } }
protected virtual void addColumn_Int(StringBuilder sb, EntityPropertyInfo ep, String columnName) { sb.Append(columnName); if (ep.Property.IsDefined(typeof(TinyIntAttribute), false)) { sb.Append(" tinyint default 0, "); } else { sb.Append(" int default 0, "); } }
/// <summary> /// 1.5新增,针对已删除用户应用 null object 模式 /// </summary> /// <param name="obj"></param> /// <param name="ep"></param> /// <param name="propertyValue"></param> public static void setEntityByCheckNull(IEntity obj, EntityPropertyInfo ep, Object propertyValue, long realUserId) { if (propertyValue == null && rft.IsInterface(ep.Type, typeof(IUser))) { IEntity user = getNullUser(realUserId); obj.set(ep.Name, user); } else { obj.set(ep.Name, propertyValue); } }
private static string getDropText(EntityPropertyInfo ep) { if (ep.EntityInfo.GetProperty("Name") != null) { return("Name"); } if (ep.EntityInfo.GetProperty("Title") != null) { return("Title"); } return(""); }
private static IEntity toEntityByMap(Type t, Dictionary <String, object> map, Type parentType) { if (map == null) { return(null); } IEntity result = Entity.New(t.FullName); EntityInfo ei = Entity.GetInfo(t); foreach (KeyValuePair <String, object> pair in map) { String pName = pair.Key; object pValue = pair.Value; EntityPropertyInfo p = ei.GetProperty(pName); Object objValue = null; if (ReflectionUtil.IsBaseType(p.Type)) { objValue = Convert.ChangeType(pValue, p.Type); } else if (p.IsList) { continue; } else if (pValue is Dictionary <String, object> ) { if (p.Type == parentType) { continue; } Dictionary <String, object> dic = pValue as Dictionary <String, object>; if (dic != null && dic.Count > 0) { objValue = toEntityByMap(p.Type, dic, t); } } else { continue; } p.SetValue(result, objValue); } return(result); }
/// <summary> /// 获取本次查询需要显示的字段集合 /// </summary> /// <param name="lstScope">范围查询集合</param> /// <returns></returns> private static string GetSelectParams(ScopeList lstScope) { if (lstScope == null) { return(AllParamNames); } StringBuilder ret = new StringBuilder(); BQLEntityTableHandle table = CurEntityInfo.DBInfo.FindTable(typeof(T)); if (CommonMethods.IsNull(table)) { CurEntityInfo.DBInfo.ThrowNotFondTable(typeof(T)); } List <BQLParamHandle> propertyNames = lstScope.GetShowProperty(table); if (propertyNames.Count > 0) { foreach (BQLParamHandle property in propertyNames) { BQLEntityParamHandle eproperty = property as BQLEntityParamHandle; if (CommonMethods.IsNull(eproperty)) { continue; } EntityPropertyInfo info = eproperty.PInfo; if (info != null) { ret.Append(CurEntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName) + ","); } } } else { foreach (EntityPropertyInfo info in CurEntityInfo.PropertyInfo) { if (info != null) { ret.Append(CurEntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName) + ","); } } } if (ret.Length > 0) { return(ret.ToString(0, ret.Length - 1)); } return(AllParamNames); }
private string getEntityNameSimple(EntityPropertyInfo ep) { if (ep.EntityInfo.GetProperty("Name") != null) { return("Name"); } if (ep.EntityInfo.GetProperty("Title") != null) { return("Title"); } return(null); }
private BQLEntityTableHandle _belongTable;//父表 /// <summary> /// 实体属性信息 /// </summary> /// <param name="entityInfo">实体信息</param> /// <param name="propertyName">属性名</param> internal BQLEntityParamHandle(EntityInfoHandle entityInfo, string propertyName, BQLEntityTableHandle belongTable) { this.entityInfo = entityInfo; if (propertyName != "*") { pinfo = entityInfo.PropertyInfo[propertyName]; if (pinfo == null) { throw new MissingMemberException(entityInfo.EntityType.FullName + "类中不包含属性:" + propertyName); } this._valueDbType = pinfo.SqlType; } _belongTable = belongTable; }
/// <summary> /// 1.5新增,针对已删除用户应用 null object 模式 /// </summary> /// <param name="obj"></param> /// <param name="ep"></param> /// <param name="propertyValue"></param> public static void setEntityByCheckNull(IEntity obj, EntityPropertyInfo ep, Object propertyValue, int realUserId) { //Mobirds //if (propertyValue == null && rft.IsInterface(ep.Type, typeof(IUser))) //{ // IEntity user = getNullUser(realUserId); // obj.set(ep.Name, user); //} //else //{ // obj.set(ep.Name, propertyValue); //} obj.set(ep.Name, propertyValue); }
private static Boolean isPropertyInIncluder( EntityPropertyInfo p, IList _includeEntityPropertyList ) { if (_includeEntityPropertyList == null) return false; if (_includeEntityPropertyList.Count == 0) return false; foreach (EntityPropertyInfo _include_ep in _includeEntityPropertyList) { if (_include_ep.Name.Equals( p.Name )) return true; } return false; }