I usually create POCO classes and place them under the Helpers namespace -they are not in my database model. Now I wonder if I should really place them under the Models namespace. How should I decide? Thank you for your h开发者_开发问答elp.
Generally speaking, POCO's refer to persistence-ignorant objects, usually directly representing models in your data tier. In other words, you might have a table called tblProducts, and a POCO called Product:
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
}
Which represents that table (but not dependant on it). Your ORM (Nhibernate, Entity Framework) can then map the table to this POCO.
With that in mind, i believe it's good practice to put your POCO's in an entirely seperate assembly, not even the same assembly as your data repository.
This way, they are kept isolated from other concerns (persistence, presentation), should not have dependencies on anything else, and are therefore truly persistent-ignorant.
If you want a bit more info on POCO's in .NET, i answered a question a few months back here.
HTH
If you're referring to your domain objects (e.g. Customer, Order) then it's actually better to put them in a separate class library project so you can reuse them from outside of your MVC app too if need be.
If those are view model or model classes then they could go in the Models
namespace. You could use the Helpers
namespace to define static classes containing extension methods for the HtmlHelper
and UrlHelper
classes.
精彩评论