private void ConfigureKey(EntityType entityType) { DebugCheck.NotNull(entityType); if (!_keyProperties.Any()) { return; } if (entityType.BaseType != null) { throw Error.KeyRegisteredOnDerivedType(ClrType, entityType.GetRootType().GetClrType()); } var keyProperties = _keyProperties.AsEnumerable(); if (!_isKeyConfigured) { var primaryKeys = from p in _keyProperties select new { PropertyInfo = p, Property(new PropertyPath(p)).ColumnOrder }; if ((_keyProperties.Count > 1) && primaryKeys.Any(p => !p.ColumnOrder.HasValue)) { throw Error.ModelGeneration_UnableToDetermineKeyOrder(ClrType); } keyProperties = primaryKeys.OrderBy(p => p.ColumnOrder).Select(p => p.PropertyInfo); } foreach (var keyProperty in keyProperties) { var property = entityType.GetDeclaredPrimitiveProperty(keyProperty); if (property == null) { throw Error.KeyPropertyNotFound(keyProperty.Name, entityType.Name); } property.Nullable = false; entityType.AddKeyMember(property); } }