0

我有 2 个项目。移动应用程序和标准网站。

我想使用 Entity Framework - Code First 在两个项目之间共享我的模型。

我如何实现这一目标?

我看了这个 Q: MVC and separate projects,这是否意味着我应该只将我的 DTO 放在单独的程序集中?

  1. 将视图模型和 DTO 放在单独的项目中是否可能和/或明智?

  2. 如果是这样,我也可以将我的模型查询放在这个单独的程序集中吗?

还有一个例子来帮助投射我的想法:

        ExtAssembly.Product product = new ExtAssembly.Product();
        product.Name = "Dave";

        ExtAssembly.ProductQueries.Create(product);

        var products = ExtAssembly.ProductQueries.Search("Dave");
4

1 回答 1

1

Is it possible and/or wise to put both View Models and DTOs inside a separate project?

Yes, it is possible, however, it might not be the right separation. View models usually are bound to the View, so they would usually stay closer to the View than the Model. I'm not sure what role your DTOs are playing here, but you want to ask yourself what concern (M,V or C) owns them and then group them there.

If so, can I also put my model queries inside this separate assembly?

Based on your example, placing the Model and your model queries in a separate assembly seems sensible. I have seen the Model separated into a new project many times. It doesn't make sense always to package the Model in the same assembly as your controllers or view for exactly the reasons you are stating in your question.

Namely, you usually want to use your Model (where the core business logic exists) for more than one UI.

于 2013-03-03T22:56:41.613 回答