Habanero.Smooth.UniqueConstraintAutoMapper.MapUniqueConstraints C# (CSharp) Method

MapUniqueConstraints() public method

Maps all the Unique Constraints for the Class.
public MapUniqueConstraints ( ) : IList
return IList
        public IList<IKeyDef> MapUniqueConstraints()
        {
            var ucNames = from propWrapper in _classType.GetProperties()
                          where propWrapper.HasUniqueConstraintAttribute && !propWrapper.IsInherited
                          select propWrapper.GetAttribute<AutoMapUniqueConstraintAttribute>().UniqueConstraintName;

            //var keyDefsLinq = from propWrapper in _classType.GetProperties()
            //              where propWrapper.HasAttribute<AutoMapUniqueConstraintAttribute>()
            //              select (IKeyDef) new KeyDef(propWrapper.GetAttribute<AutoMapUniqueConstraintAttribute>().UniqueConstraintName);

            var keyDefs = ucNames.Distinct().ToList().ConvertAll(s => (IKeyDef)new KeyDef(s));

            keyDefs.ForEach(keyDef =>
                                {
                                    var propNames =
                                        from propWrapper in _classType.GetProperties()
                                        where propWrapper.HasUniqueConstraintAttribute &&
                                              propWrapper.GetAttribute<AutoMapUniqueConstraintAttribute>().UniqueConstraintName == keyDef.KeyName
                                        select propWrapper.Name;

                                    var p = propNames.ToList();

                                    var propDefs =
                                        from propDef in ClassDef.PropDefcol
                                        where propNames.Contains(propDef.PropertyName)
                                        select propDef;

                                    propDefs.ToList().ForEach(keyDef.Add);

                                    var col = ClassDef.RelationshipDefCol;
                                    var rels = col.Where(def => propNames.Contains(def.RelationshipName));
                                    var props = rels.SelectMany(def => def.RelKeyDef.Select(propDef => ClassDef.PropDefcol[propDef.OwnerPropertyName]));
                                    props.ForEach(keyDef.Add);
                                });

            return keyDefs;
        }

Usage Example

        /// <summary>
        /// Automaps all the unique constrainst for the ClassType defined by the <paramref name="classDef"/> using reflection
        /// </summary>
        /// <param name="classDef"></param>
        /// <returns></returns>
        public static IList<IKeyDef> MapUniqueConstraints(this IClassDef classDef)
        {
            if (classDef == null) return new List<IKeyDef>();
            UniqueConstraintAutoMapper autoMapper = new UniqueConstraintAutoMapper(classDef);

            return autoMapper.MapUniqueConstraints();
        }
All Usage Examples Of Habanero.Smooth.UniqueConstraintAutoMapper::MapUniqueConstraints