public DocumentMapping(Type documentType, StoreOptions options) { DocumentType = documentType; Alias = defaultDocumentAliasName(documentType); IdMember = (MemberInfo)documentType.GetProperties().FirstOrDefault(x => x.Name.EqualsIgnoreCase("id")) ?? documentType.GetFields().FirstOrDefault(x => x.Name.EqualsIgnoreCase("id")); if (IdMember == null) { throw new InvalidDocumentException( $"Could not determine an 'id/Id' field or property for requested document type {documentType.FullName}"); } assignIdStrategy(documentType, options); documentType.ForAttribute <MartenAttribute>(att => att.Modify(this)); documentType.GetProperties().Where(x => TypeMappings.HasTypeMapping(x.PropertyType)).Each(prop => { var field = new LateralJoinField(prop); _fields[field.MemberName] = field; prop.ForAttribute <MartenAttribute>(att => att.Modify(this, prop)); }); documentType.GetFields().Where(x => TypeMappings.HasTypeMapping(x.FieldType)).Each(fieldInfo => { var field = new LateralJoinField(fieldInfo); _fields.AddOrUpdate(field.MemberName, field, (key, f) => f); fieldInfo.ForAttribute <MartenAttribute>(att => att.Modify(this, fieldInfo)); }); }
public DocumentMapping(Type documentType) { DocumentType = documentType; IdMember = (MemberInfo)documentType.GetProperties().FirstOrDefault(x => x.Name.EqualsIgnoreCase("id")) ?? documentType.GetFields().FirstOrDefault(x => x.Name.EqualsIgnoreCase("id")); TableName = TableNameFor(documentType); UpsertName = UpsertNameFor(documentType); documentType.GetProperties().Where(x => TypeMappings.HasTypeMapping(x.PropertyType)).Each(prop => { var field = new LateralJoinField(prop); _fields[field.MemberName] = field; }); documentType.GetFields().Where(x => TypeMappings.HasTypeMapping(x.FieldType)).Each(fieldInfo => { var field = new LateralJoinField(fieldInfo); _fields.AddOrUpdate(field.MemberName, field, (key, f) => f); }); }