public EntityTypeConfiguration <TEntityType> HasKey <TKey>(Expression <Func <TEntityType, TKey> > keyExpression) { Check.NotNull(keyExpression, "keyExpression"); _entityTypeConfiguration.Key(keyExpression.GetSimplePropertyAccessList().Select(p => p.Single())); return(this); }
public void Cloning_an_entity_configuration_clones_its_key_information() { var configuration = new EntityTypeConfiguration(typeof(object)); var mockPropertyInfo1 = new MockPropertyInfo(typeof(int), "P1"); configuration.Property(new PropertyPath(mockPropertyInfo1)).ColumnOrder = 0; var mockPropertyInfo2 = new MockPropertyInfo(typeof(int), "P2"); configuration.Property(new PropertyPath(mockPropertyInfo2)).ColumnOrder = 1; // This will set _isKeyConfigured to true configuration.Key( new List <PropertyInfo> { mockPropertyInfo1 }); var clone = configuration.Clone(); VerifyKeyProperty(clone, "P1", mockPropertyInfo1, mockPropertyInfo2); // This should have no effect because _isKeyConfigured is set to true clone.Key(mockPropertyInfo2); VerifyKeyProperty(clone, "P1", mockPropertyInfo1, mockPropertyInfo2); // This should change the key on the original, but not on the clone. configuration.Key( new List <PropertyInfo> { mockPropertyInfo2 }); VerifyKeyProperty(configuration, "P2", mockPropertyInfo1, mockPropertyInfo2); VerifyKeyProperty(clone, "P1", mockPropertyInfo1, mockPropertyInfo2); }