我应该如何命名数据库包装器对象? [英] How should I name database wrapper object?

查看:137
本文介绍了我应该如何命名数据库包装器对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的CMS应用程序,我正在编写一个我将包含在我的项目中的DLL。该DLL将包括检索特定项目的所有新闻的功能。

For my CMS application I'm writing a DLL that I will include into my projects. That DLL will include functionality like retrieving all news for a specific project.

例如,我的数据库包含一个名为News的表。通过使用实体框架4,我有一个名为新闻的自动生成的类。我不希望我的DLL方法返回此对象,而不是一个包装类,只包含属性。

For instance, my database contains a table called News. By using the Entity Framework 4 I have a automatic generated class called News. I do not want my DLL methods return this object rather than a wrapper class, that only contains properties.

我应该如何命名这个包装类?
现在我总是附加容器这个词,但是在这段时间我不喜欢这个后缀。意思是,我现在将这个类命名为 NewsContainer

How should I name this wrapper class? For now I've always appended the word "Container", but over the time I do dislike this suffix. Meaning, I would now name this class NewsContainer.

当然我也可以将这个包装类命名为新闻。这将工作,因为我将在两个独立的命名空间中有两个类,但我宁愿不同名两个不同的类。是不是,两个名字不同的班级是一样的?我问这个,因为新闻实际上是最适合的名字。

Of course I could name this wrapper class also News. This would work because I'd have two classes in two separate namespaces, but I'd rather not name two different classes the same. Is is ok, two name to different classes the same? I'm asking this, because News would actually the best name fit.

编辑:我手动映射我自己的包装类和自动生成的实体框架类之间的属性,如果这是重要的。

Edit: I do manually map the properties between my own wrapper class and the automatic generated entity framework class, if that is of any importance.

推荐答案

同意您的包装/ DTO类的初始命名为新闻。将它们保存在具有相同名称的单独命名空间中是完全正确的。这就是命名空间的一部分:减少命名中的冲突。

I'd agree with your initial naming of your wrapper/DTO class as News. Keeping them in separate namespaces with the same names is perfectly fine. That's part of what namespaces are for: to reduce collisions in naming.

我会画出这样的东西$ /

I'd sketch out something like this

namespace MyCmsApp.Models
{
    public class News {
        public string Title { get; set; }
        public string Body { get; set; }
        public string Author { get; set; }
    }
}

然后我将DataLayer只返回类型在 MyCmsApp.Models 中。换句话说,正如你所建议的那样,EF生成的类不会越过你的应用程序。

I'd then have the DataLayer return only types within the MyCmsApp.Models. In other words, as you were suggesting, the EF generated classes don't cross over into your app.

旁注:你为什么要避免使用EF类?你会考虑代码优先和/或Model-First设计?在这些情况下,数据库会弯曲到应用程序的对象模型设计。

Side note: why are you trying to avoid using the EF classes? Would you consider code-first and/or Model-First design? In those scenarios, the database bends to your application's object model design.

这篇关于我应该如何命名数据库包装器对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆