Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Edited Issue: [RTM] EntityType.DeclaredMembers is not accessible with a string key [1567]

$
0
0
## SUMMARY

EntityType.DeclaredMembers is a ReadOnlyMetadataCollection. It's currently accessible with an **int** key, but if you try to access it with a **string** key, it throws an exception.

## REPRO
```
[Fact]
public void declared_members_should_be_accessible_by_name()
{
var model = new EdmModel(DataSpace.CSpace);
var typeMapper = new TypeMapper(new MappingContext(new ModelConfiguration(),
new ConventionsConfiguration(), model));

var mockObjectType = new MockType("Blog")
.Property<int>("Id")
.Property<string>("Title")
;

new MockAssembly(mockObjectType);
var entityType = typeMapper.MapEntityType(mockObjectType);

Assert.NotNull(entityType.DeclaredMembers[0]); // #1
Assert.NotNull(entityType.DeclaredMembers[1]); // #2
Assert.NotNull(entityType.DeclaredMembers["Id"]); // #3
Assert.NotNull(entityType.DeclaredMembers["Title"]);// #4
}
```

## RESULT

Asserts #1 and #2 pass, but #3 and #4 fail with the following message:

**Exception**
System.InvalidCastException : Unable to cast object of type 'System.Collections.Generic.List`1[System.Data.Entity.Core.Metadata.Edm.EdmMember]' to type 'System.Data.Entity.Core.Metadata.Edm.MetadataCollection`1[System.Data.Entity.Core.Metadata.Edm.EdmMember]'.

**Stack Trace**
at System.Data.Entity.Core.Metadata.Edm.ReadOnlyMetadataCollection`1.get_Item(String identity) in c:\docs\entityframework\src\EntityFramework\Core\Metadata\Edm\ReadOnlyMetadataCollection.cs:line 126
at System.Data.Entity.ModelConfiguration.Edm.TypeMapperTests.Declared_members_should_be_accessible_by_name() in c:\docs\entityframework\test\EntityFramework\UnitTests\ModelConfiguration\Mappers\TypeMapperTests.cs:line 37


Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>