среда, 2 апреля 2014 г.

VS 2013 Web API Add Controller Dialogs - How to add Model and Context from Referenced Library?

Copy from Here

http://stackoverflow.com/questions/20976962/vs-2013-web-api-add-controller-dialogs-how-to-add-model-and-context-from-refer


Adding a controller in a Web API project works very well - only if your models and EF data context are in the same assembly as the project itself - i.e., located in the project's Models folder.
I created all the POCOs and EF data context in a separate library project, created the library, and referenced it from the Web API project. Unfortunately, the dialogs can only see models and data context whose .cs files reside in the project.
I've looked at similar questions and somehow, other people's add controller dialogs list their models and data contexts from external (referenced) libraries (then they have a different problem, which my problem isn't getting to (yet)).
Is there such a setting (in the IDE or web.config) that I need to specify so that these add controller dialogs will see my library's classes?
share|improve this question
add comment
So far, I've come up with a "dirty" workaround, which I'm not very satisfied, though it works:
  1. Create a dummy class under /Models with arbitrary properties – but one of them has to be int Id.
  2. Go through the add controller dialogs and choose the dummy model.
  3. If you haven’t created a data context, click on New data context. Beware that the dialog will auto-generate the full qualified namespace path of the data context, and that the context name contains a space. Remove it. Click add.
  4. Open the auto-generated controller .cs file.
  5. Reference your library in this .cs file that contains the model and the context.
  6. Find and replace all instances of the dummy class with the actual model’s class name you need. Be careful of plurals. String-replace plurals first, then singular after.
  7. Change the dummy context class to the correct data context class.

Комментариев нет:

Отправить комментарий