gpt4 book ai didi

c# - 没有 ORM 的数据访问层

转载 作者:行者123 更新时间:2023-11-30 15:01:25 24 4
gpt4 key购买 nike

我正在编写 mmorpg 服务器模拟器(业余项目)并且我已经停止编写数据访问层。问题是我不能使用 ORM(性能问题)。我已经阅读了很多关于存储库模式的内容,但它似乎不太适合我的项目,因为我需要这样的方法:(player db) GetAllByLevel(...)、GetByName(...) 等。我希望我的应用程序与数据库无关。 (我现在使用的是 sql server,但我想稍后添加对 mysql 的支持)哪种数据访问模式适合我的项目?

抱歉我的英语不好。

编辑

还有一个问题。我读过存储库模式在聚合根上运行。我有 3 个表 player,player_friend 和 player_chest。 Player 是一个聚合根,如果我没记错的话,我应该只创建一个存储库 (PlayerRepository),它可以包含以下方法:GetFriends([player id], ...), GetChest([player id], ...)等等。我说得对吗?

最佳答案

I've read a lot about Repository pattern but it seems like it does not fit well into my project because I'm gonna need methods like: (player db) GetAllByLevel(...), GetByName(...), etc.

恰恰相反。有很多错误的存储库模式示例(通常是泄漏的抽象)教你错了。 GetAllByLevel 是一个很好的方法,因为它非常清楚地描述了方法的作用。

我写过关于存储库模式的文章:http://blog.gauffin.org/2013/01/repository-pattern-done-right/ .另请阅读文章开头的抽象链接。

The thing is that i can't use ORM (performance matter).

没问题。存储库模式用于抽象出数据源,无论是哪种数据源。

如果您想使用普通的 ADO.NET,您可以阅读这篇博文:http://blog.gauffin.org/2013/01/ado-net-the-right-way/

One more question. I've read that repository pattern operates on the agreggate root. I've got 3 tables player, player_friend and player_chest. Player is an agreggate root and if i'm not wrong i should create just one repository (PlayerRepository) that could have methods like: GetFriends([player id], ...), GetChest([player id], ...) and so on. Am i right?

没有。我会说 Friends 也是根。阅读这篇关于聚合设计的文章:http://dddcommunity.org/library/vernon_2011

关于c# - 没有 ORM 的数据访问层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14293053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com