Tutorial :Force Entity Framework to ignore all foreign keys during class generation



Question:

I am using the Entity Framework just to create classes that can be mapped to database tables. We have our own data access layer that I need to go through, which is why I'm only using the generated classes.

I would like the entity framework to generate foreign keys as properties instead of classes. So, basically, when it generates classes, I need it to ignore all the foreign keys.

Alternatively, I'm OK with deleting the FK links manually, but I can't figure out how to then regenerate the classes other than syncing from the DB.

I know that .Net 4.0 beta should support this out of the box with the new FK associations, but we're not ready to move up to this, yet. I was thinking that I may be able to use .Net 4.0 to generate the classes and plug them into my 3.5 project, but I doubt this would be smooth sailing.

Anybody have any ideas?

Thanks so much for any input.


Solution:1

You can check a box in the EF wizard "Include foreign key columns in the model” which generates both a navigation link and properties for foreign keys.


Solution:2

Well, I just sucked it up and created partial classes to expose foreign keys as properties. If anybody knows a better way, please let me know.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »