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

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

问题描述

有关我的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.

例如,我的数据库包含了一个名为新闻表。通过使用实体框架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; }
    }
}

我会再有数据层内的 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类?你会考虑 code-第一和/或模型的第一个设计?在这些情况下,数据库弯曲到应用程序的对象模型设计。

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天全站免登陆