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;
}