Linq2Sql 生成的类能够放入单独的项目中吗?

发布于 2024-08-05 19:12:19 字数 391 浏览 1 评论 0原文

谁能告诉我是否可以将 linq2sql 生成的类提取到 C# 中的单独项目中? - 我想我可以创建文件,然后将它们复制到新项目并添加对我的数据项目的引用?

我遇到的问题是我有 UI、服务层和数据层...

目前数据层也有生成的 linq2sql,因为这是 dbml 所在的位置。

因此我需要有一个从服务到数据的参考,这很好!但我有我的 UI 来引用服务层,但我不认为我的 UI 引用数据层是个好主意(因为 linq2sql 类需要它)。

因此,我看到的唯一方法是将类取出并放置在一个单独的项目中,以便所有项目都可以共享。这是好的做法吗?

我应该用什么命名约定来称呼这个项目,DTO?波科?实体?或类似的,

我真的很想听到一些关于如何实现这一目标的反馈,以及我是否是正确的路线

Can anyone tell me if its possible to extract the linq2sql generated classes into a separate project in c#? - I presume I can just create the files and then copy them to a new project and add a reference to my Data project?

The problem I have is that I have my UI, Service Layer and Data layer...

Currently the data layer also has the generated linq2sql as this is where the dbml is.

So hence I need to have a reference from service to data, which is good! But I have my UI to reference the service layer but I don't think its a good idea for my UI to have a reference to the data layer (as it would need it for the linq2sql classes).

So the only way I see is to pull out the classes and place in a separate project so that all projects can share. Is this good practice?

What naming conventions should I call this project, DTO? POCO? Entities? or similar

I really would love to hear some feed back of how to accomplish this and weather I am the right lines

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

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

发布评论

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

评论(1

野侃 2024-08-12 19:12:19

我不是 100% 确定这是否也适用于 Linq2Sql(我想是的),但这就是我对 Linq2Entities 所做的事情:

生成类后,我手动将它们移动到不同的项目。我通常称这个项目为xxxxxx.Model。实体也可能没问题,但我会远离 DTO 和 POCO,因为这些类都不是。我相信有一种方法可以使用 Linq2Sql 进行 POCO,但如果您使用设计器则不行。然后,我根据需要添加对其他层的引用。

希望这有帮助。

I'm not 100% sure if this also works for Linq2Sql (I imagine it does), but this is what I do with Linq2Entities:

Once the classes have been generated, I manually move them to a different project. I usually call this project xxxxxx.Model. Entities would probably also be alright but I would stay away from DTO and POCO because those classes are neither. I believe there is a way to do POCO with Linq2Sql, but not if you use the designer. I then add references as needed to the other layers.

Hope this helps.

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