private IEnumerable <string> GetKeys <T>(MetadataContainer container) where T : class { var typeDescr = container.GetTypeDescriptor(typeof(T)); var properties = typeDescr.GetProperties().OfType <PropertyDescriptor>(); var result = properties.Where(p => p.Attributes[typeof(KeyAttribute)] != null).Select(x => x.Name).ToList(); return(result); }
/// <summary> /// A linkTable entity contains many properties that can be annotated as KeyAttribute. In this method we mark all of them to be excluded (using the ExceludeAttribute), except for /// those of them that are actually allocated as key properties. This way, the generated entity at the client will only have properties that really are KeyAttributes. /// </summary> /// <param name="metaData"> </param> private void MarkLinkTableKeysAsDataMembers(MetadataClass <TLinkTable> metaData) { var linkTableMetaData = _metaDataContainer.Entity <TLinkTable>(); var typeDescr = _metaDataContainer.GetTypeDescriptor(typeof(TLinkTable)); foreach (var propDescr in typeDescr.GetProperties().OfType <PropertyDescriptor>()) { var memberMetadata = metaData.GetMemberMetadata(propDescr.Name); if (memberMetadata == null || (memberMetadata.OfType <KeyAttribute>().Any() == false && memberMetadata.OfType <AssociationAttribute>().Any() == false)) { linkTableMetaData.AddMetadata(propDescr.Name, new ExcludeAttribute()); } } }