문제

I am new to EF and i can't work out what I am doing wrong. I have used EF 4.1 "database first" to create a model for an existing database (that i can't change). All of the tables that i need in the database are in a particular schema which for this question i will call "my_schema". In the main properties of the edmx designer file i have set Database Schema Name to "my_schema". When i inspect the raw XML of the edmx file it seems to have the correct schema mappings

e.g.

<EntitySet Name="Events" EntityType="MyModel.Store.Events" store:Type="Tables" Schema="my_schema" />

However the SQL generated when i access the Events entity set on the DbContext class is still:

SELECT ....
FROM dbo.Events

I am not sure if it makes any difference but i am using the ADO.net DBContextGenerator to generate my classes.

Does anybody know what I am doing wrong.

도움이 되었습니까?

해결책

OK i have sussed this now and it boils down to my ignorance of how EF works. I was passing my DbContext an ordinary ADO.net connection string which seems to flip it into code first mode. As such any settings and configuration in my edmx model were ignored and it was looking for attributes on the model classes. As soon as i changed it to use an EF string that includes references to the model metadata files it works. Seems obvious now, no idea how i expected it to magically know about model metadata.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top