跨项目拆分命名空间

发布于 2024-09-30 01:36:10 字数 601 浏览 0 评论 0原文

我似乎在跨项目拆分命名空间时遇到问题。

我有一个 DatabaseAccess 项目,其中有一个名为 SCS(Some Crazy System)的文件夹,它提供对 SCS 数据库的数据访问。现在,此 SCS 具有实体框架 (.edmx) 生成的实体。我想在我的 BusinessModel 项目中扩展这些实体。然而我似乎无法这样做。下面是我的例子。我正在创建一个分部类,并创建一个与我的实际 DatabaseAccess 项目中的命名空间同名的命名空间:

namespace DatabaseAccess.SCS{
    public partial SomeEntity{
         public void DoSomething(){
             var x = this.GeneratedField;
         }
    }
}

执行上述操作不起作用。它抱怨 GenerationField 不是 SomeEntity 类的一部分,尽管它是。如果我弹出 edmx 的 SCS.Designer,SomeEntity 确实有 GenerationField 的定义,并且 SomeEntity 是 DatabaseAccess.SCS 命名空间的一部分。什么给?

I seem to be having trouble splitting a namespace across projects.

I have a DatabaseAccess project which has a folder called SCS (Some Crazy System) which provides data access to the database for SCS. Now this SCS has entity framework (.edmx) generated entities. I would like to extend these entities in my BusinessModel project. However I don't seem to be able to do so. below is my example. I am creating a partial class and also creating a namespace with the same name as the namespace in my actual DatabaseAccess project:

namespace DatabaseAccess.SCS{
    public partial SomeEntity{
         public void DoSomething(){
             var x = this.GeneratedField;
         }
    }
}

Doing the above doesn't work. It complains that GeneratedField is not part of the SomeEntity class even though it is. If i pop open the SCS.Designer for the edmx, SomeEntity indeed does have a definition for the GeneratedField and SomeEntity is part of the DatabaseAccess.SCS namespace. What gives?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

百善笑为先 2024-10-07 01:36:10

您不仅将命名空间拆分为多个项目,还拆分了类。我怀疑这是可能的,因为构造这样的对象通常非常困难,因为每个对象通常都严重依赖于......好吧,它本身! (扩展方法虽然可以提供类似的功能 - 尽管我不建议过度使用它们。文档也没有。)

为什么不在同一个项目中将该部分作为它的其他部分呢?

You're not just splitting the namespace across multiple projects there, but the class too. I doubt that's possible as it would usually be very difficult to construct such objects as each object usually has heavy dependencies on... well, itself! (Extension methods could though provide similar functionality - although I don't recommend overusing them. Neither does the documentation.)

Why don't you just have that partial in the same project as the other part of it?

倒带 2024-10-07 01:36:10

如果分部类不在同一项目中,则必须添加对从其他项目构建的程序集的引用。否则,本地项目尚不知道该类以扩展它。

If the partial class isn't in the same project, you'll have to add a reference to the assembly built from the other project. Otherwise the local project doesn't already know the class in order to extend it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文