Entity Framework 4.1 RC POCO - Unit Test the name of produced field names
Is it possible to access metadata about a POCO entity using EF4.1 that states what the database field names are? Most importantly on foreign key values.
I would like to access this for the purpose of unit testing whilst trying to apply EF4.1 to an existing database schema. I cannot change the existing column names.
Currently the tests create the database using SQL Server Compact 4.0 so I can see the names of the fields, but it would be better if this was automated.
Pseudo code for a test being
- Cre开发者_如何学编程ate entity
- Save entity
- Check that the field name is as expected
That is not unit testing. That is integration testing. Moreover such tests are not too much usefull. Don't let EF create database and instead use copy of the existing database. Simply save entity and load entity in a new context. If data are ok you are happy with it. You can make each test transactional so the transaction is rolled back after each test.
EF 4.1 with code-first approach doesn't offer access to metadata workspace. You can try to convert DbContext
back to ObjectContext
and try to access MetadataWorkspace
:
ObjectContext ctx = ((IObjectContextAdapter) context).ObjectContext;
MetadataWorkspace workspace = ctx.MetadataWorkspace;
Searching anything in MetadataWorkspace
is terrible experience. That class is definitely not designed to be used in custom code.
精彩评论