开发者

Where to put metadata in use with EF and global resources

开发者 https://www.devze.com 2023-02-06 11:28 出处:网络
I have a project with a website and a assembly project containing logic functions used by several other projects.

I have a project with a website and a assembly project containing logic functions used by several other projects.

The entity framework model is in the logic project so it can be used between projects. I have also created partial classes here with Metadata (display name, required attributes and such).

So far so good.. But now when I'm implementing localization I need to get the display names from the global resources, which is in the website project. Even if there is some way to add a reference to this, it would make a circular reference.

Anyone got a good idea of how to 开发者_开发百科set this up? It's not to late to move the metadata to the website if that is what I should do.


You shouldn't put any globalization or formatting attributes on your models. You should use View Models inside your web tier. Those view models are classes which are specifically tailored to the needs of a given view. It is those view models that will contain attributes about the formatting and globalization required by this specific view.

So here's the usual controller action workflow:

  1. The action queries a repository to fetch a model
  2. The action maps this model to a view model
  3. The action returns passes this view model to the view

To ease the mapping between your models and view models you could use AutoMapper.

0

精彩评论

暂无评论...
验证码 换一张
取 消