Esempio n. 1
0
 public virtual BaseNonPersistent Clone(IObjectMap map)
 {
     throw new Exception("Clone needs to be overriden");
     //var clone = (BaseNonPersistent)Activator.CreateInstance(this.GetType(), this.ID, this.Name);
     //map.AcceptObject(clone);
     //return clone;
 }
Esempio n. 2
0
        private IObjectMap FindMap(IDictionary <Object, IObjectMap> dic, Object id, Boolean extend = false)
        {
            IObjectMap map = null;

            // 名称不能是null,否则字典里面会报错
            if (id == null)
            {
                id = String.Empty;
            }
            // 如果找到,直接返回
            if (dic.TryGetValue(id, out map) || dic.TryGetValue(id + "", out map))
            {
                return(map);
            }

            //if (!String.IsNullOrEmpty(id))
            if (id == null || "" + id == String.Empty)
            {
                // 如果名称不为空,则试一试找空的
                if (dic.TryGetValue(String.Empty, out map))
                {
                    return(map);
                }
            }
            else if (extend)
            {
                // 如果名称为空,找第一个
                foreach (var item in dic.Values)
                {
                    return(item);
                }
            }
            return(null);
        }
Esempio n. 3
0
        static MapperFactory()
        {
            //初始化
            var autoMapper = new AutoMapMapper();

            autoMapper.Register();
            objectMapper = autoMapper;
        }
Esempio n. 4
0
        public override string GetSql(DynamicParameters parameters, IObjectMap objectMap)
        {
            var sql = String.Empty;

            if (IsValidPropertyName(this.PropertyName) && IsValidPropertyName(this.PropertyName2))
            {
                var columnName  = GetColumnName <T>(objectMap, this.PropertyName !, false);
                var columnName2 = GetColumnName <T2>(objectMap, this.PropertyName2 !, false);
                sql = $"{CommandAdapter.LeftParenthesis}{columnName}{this.GetOperatorString()}{columnName2}{CommandAdapter.RightParenthesis}";
            }

            return(sql);
        }
Esempio n. 5
0
        private static string GetTableName(IObjectMap objectMap, string alias)
        {
            Contracts.Requires.NotNull(objectMap, nameof(objectMap));

            var result = new StringBuilder();

            result.Append(objectMap.FullyQualifiedObjectName);
            if (!String.IsNullOrWhiteSpace(alias))
            {
                result.Append($"{CommandAdapter.As}{objectMap.CommandAdapter.QuoteIdentifier(alias)}");
            }

            return(result.ToString());
        }
Esempio n. 6
0
        public string GetSql(DynamicParameters parameters, IObjectMap objectMap)
        {
            var sql = String.Empty;

            if (this.Predicate != null)
            {
                var operatorString = this.Not ? CommandAdapter.NotExists : CommandAdapter.Exists;
                if (objectMap != null)
                {
                    sql = $"{CommandAdapter.LeftParenthesis}{operatorString}{CommandAdapter.SpaceLeftParenthesis}{CommandAdapter.SelectOne}{objectMap.ObjectName}{CommandAdapter.Where}{this.Predicate.GetSql(parameters, objectMap)}{CommandAdapter.RightParenthesis}{CommandAdapter.RightParenthesis}";
                }
            }

            return(sql);
        }
Esempio n. 7
0
        public string GetSql(DynamicParameters parameters, IObjectMap objectMap)
        {
            var seperator     = this.Operator == GroupOperator.And ? CommandAdapter.And : CommandAdapter.Or;
            var predicateList = new List <string>();

            foreach (var predicate in this.Predicates)
            {
                var sql = predicate.GetSql(parameters, objectMap);
                if (!String.IsNullOrWhiteSpace(sql))
                {
                    predicateList.Add(sql);
                }
            }

            return(predicateList.Any() ? $"{CommandAdapter.LeftParenthesis}{ String.Join(seperator, predicateList) }{CommandAdapter.RightParenthesis}" : String.Empty);
        }
Esempio n. 8
0
        public static IObjectMap CreateMap(DatabaseObjectType databaseObjectType, CommandAdapter commandAdapter)
        {
            IObjectMap map = null;

            switch (databaseObjectType)
            {
            case DatabaseObjectType.Table:
                map = new TableMap <T>(commandAdapter);
                break;

            case DatabaseObjectType.View:
                map = new ViewMap <T>(commandAdapter);
                break;
            }

            return(map);
        }
Esempio n. 9
0
        public override string GetSql(DynamicParameters parameters, IObjectMap objectMap)
        {
            if (this.Value != null && IsValidPropertyName(this.PropertyName))
            {
                var columnName = GetColumnName <T>(objectMap, this.PropertyName !, false);

                if (this.Operator == Operator.In)
                {
                    if (this.Value is IEnumerable enumerable)
                    {
                        var @params = new List <string>();
                        foreach (var value in enumerable)
                        {
                            var valueParameterName = parameters.SetParameterName(this.PropertyName !, value, '@');
                            @params.Add(valueParameterName);
                        }

                        if (@params.Any())
                        {
                            var paramStrings = @params.Aggregate(new StringBuilder(), (sb, s) => sb.Append((sb.Length != 0 ? ", " : String.Empty) + s), sb => sb.ToString());
                            return($"{CommandAdapter.LeftParenthesis}{columnName}{this.GetOperatorString()}{CommandAdapter.SpaceLeftParenthesis}{paramStrings}{CommandAdapter.RightParenthesis}{CommandAdapter.RightParenthesis}");
                        }
                        else
                        {
                            return(String.Empty);
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Value must be enumerable for IN operations");
                    }
                }

                if (this.Operator == Operator.Between && this.Value is Tuple <TFieldType, TFieldType> values && values.Item1 != null && values.Item2 != null)
                {
                    return($"({columnName} {this.GetOperatorString()} {parameters.SetParameterName(this.PropertyName!, values.Item1, '@')}{CommandAdapter.And}{parameters.SetParameterName(this.PropertyName!, values.Item2, '@')})");
                }

                var parameterName = parameters.SetParameterName(this.PropertyName !, this.Value, '@');
                return($"({columnName} {this.GetOperatorString()} {parameterName})");
            }

            return(String.Empty);
        }
Esempio n. 10
0
        internal static string GetColumnName <T>(IObjectMap objectMap, string propertyName, bool alias) where T : class
        {
            string?columnName = null;

            if (objectMap != null && IsValidPropertyName(propertyName))
            {
                var propertyMap = objectMap.Properties.SingleOrDefault(p => p.PropertyName == propertyName);
                if (propertyMap != null)
                {
                    string?columnAlias = null;
                    if (propertyMap.ColumnName != propertyMap.PropertyName && alias)
                    {
                        columnAlias = propertyMap.PropertyName;
                    }

                    columnName = GetColumnName(objectMap.CommandAdapter, GetTableName(objectMap, null), propertyMap.ColumnName, columnAlias);
                }
            }

            return(columnName ?? throw new InvalidOperationException($"Property '{propertyName}' was not found for {typeof(T)}."));
        }
Esempio n. 11
0
 public abstract string GetSql(DynamicParameters parameters, IObjectMap objectMap);
Esempio n. 12
0
        private IObjectContainer Register(Type from, Type to, Object instance, String typeName, ModeFlags mode, Object id, Int32 priority /*, Boolean singleton = false*/)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            // 名称不能是null,否则字典里面会报错
            if (id == null)
            {
                id = String.Empty;
            }

            var        dic = Find(from, true);
            IObjectMap old = null;
            Map        map = null;

            if (dic.TryGetValue(id, out old) || dic.TryGetValue(id + "", out old))
            {
                map = old as Map;
                if (map != null)
                {
                    // 优先级太小不能覆盖
                    if (priority <= map.Priority)
                    {
                        return(this);
                    }

                    map.TypeName      = typeName;
                    map.Mode          = mode;
                    map.ImplementType = to;
                    map.Instance      = instance;
                    //map.Singleton = instance != null || singleton;

                    if (OnRegistering != null)
                    {
                        OnRegistering(this, new EventArgs <Type, IObjectMap>(from, map));
                    }
                    if (OnRegistered != null)
                    {
                        OnRegistered(this, new EventArgs <Type, IObjectMap>(from, map));
                    }

                    return(this);
                }
                else
                {
                    dic.Remove(id);
                }
            }

            map          = new Map();
            map.Identity = id;
            map.TypeName = typeName;
            map.Mode     = mode;
            map.Priority = priority;
            if (to != null)
            {
                map.ImplementType = to;
            }
            if (instance != null)
            {
                map.Instance = instance;
            }
            //map.Singleton = instance != null || singleton;

            if (!dic.ContainsKey(id))
            {
                if (OnRegistering != null)
                {
                    OnRegistering(this, new EventArgs <Type, IObjectMap>(from, map));
                }
                dic.Add(id, map);
                if (OnRegistered != null)
                {
                    OnRegistered(this, new EventArgs <Type, IObjectMap>(from, map));
                }
            }

            return(this);
        }
Esempio n. 13
0
 public void AddObjectMap(IObjectMap objectmap)
 {
     objectsOnMap[0] = objectmap;
 }
Esempio n. 14
0
        private IObjectContainer Register(Type from, Type to, Object instance, String typeName, Object id, Int32 priority)
        {
            if (from == null)
            {
                throw new ArgumentNullException("from");
            }
            // 名称不能是null,否则字典里面会报错
            if (id == null)
            {
                id = String.Empty;
            }

            var        dic = Find(from, true);
            IObjectMap old = null;
            Map        map = null;

            if (dic.TryGetValue(id, out old) || dic.TryGetValue(id + "", out old))
            {
                map = old as Map;
                if (map != null)
                {
                    // 优先级太小不能覆盖
                    if (priority <= map.Priority)
                    {
                        return(this);
                    }

                    map.TypeName      = typeName;
                    map.ImplementType = to;
                    map.Instance      = instance;

                    return(this);
                }
                else
                {
                    lock (dic)
                    {
                        dic.Remove(id);
                    }
                }
            }

            map          = new Map();
            map.Identity = id;
            map.TypeName = typeName;
            map.Priority = priority;
            if (to != null)
            {
                map.ImplementType = to;
            }
            if (instance != null)
            {
                map.Instance = instance;
            }

            if (!dic.ContainsKey(id))
            {
                lock (dic)
                {
                    if (!dic.ContainsKey(id))
                    {
                        dic.Add(id, map);
                    }
                }
            }

            return(this);
        }
Esempio n. 15
0
 public string GetSql(DynamicParameters parameters, IObjectMap objectMap)
 {
     return(String.Empty);
 }
Esempio n. 16
0
 public Table(Database database)
 {
     this.database = database;
     this.tableMap = database.MapObject <TEntity>(this.ObjectType);
 }
Esempio n. 17
0
 public UserRepository(HTDbContext dbContext, IObjectMap objectMap) : base(dbContext)
 {
     _objectMap = objectMap;
 }
Esempio n. 18
0
 public View(Database database)
 {
     this.database = database;
     this.viewMap  = database.MapObject <TEntity>(this.ObjectType);
 }
 public EntityFrameworkAdvertRepository()
 {
     this.db     = new CarTraderContext();
     this.mapper = new AutoMapperMap();
 }
Esempio n. 20
0
 public virtual void CopyTo(BaseNonPersistent target, IObjectMap map)
 {
     throw new Exception("CopyTo needs to be overriden");
 }