简体   繁体   中英

Entity Framework - in model first, how do I get my EF classes to be based on the existing domain classes I have?

If I already have domain classes, and I want to be able persist them using EF via a model first approach how do I do this?

For example do I go to the EF designer (in VS2010) and create the model and generate the classes, then go to these EF classes and somehow manually modify them? But then would there be an issue if I needed to change the model and re-create database TSQL from the model for updates?

What's the easiest approach?

EDIT - In my case I've got some base classes that do graph navigation - I was hoping I could leave (a) my graph traversal routines in the business logic assembly, eg NodeBase, RelationshipBase etc, and then (b) have my EF persistance in a separate EF assembly. Any advice on this specific scenario I have?

EDIT 2 - Actually I note I note the following template options from "Add Code Generation Item.."

  1. ADO.NET C# POCO Entity Generator Template - Online
  2. ADO.NET Self-Tracking Entity Generator - Local
  3. ADO.NET Entity Object Generator

I'm guessing the #3 one is the default that comes with VS2010. Anyone across #1 and #2 and which might be best to assist in my goal? ie Having an existing set of domain classes with methods that already inherit from other classes (ie noting with the current EF generated entity classes they seem to already have to inherit from EntityObject)

The generated classes are all partial. So if you have the same namespace and same Entity/Class names it's fairly easy to merge an existing set of classes with a model-first set of entities. Simply put partial on your class and remove all the properties that are implemented by the Entity framework generated code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM