带有 NoSQL API 的 ORM 是多余的吗? [英] Is an ORM redundant with a NoSQL API?

查看:23
本文介绍了带有 NoSQL API 的 ORM 是多余的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 MongoDB(我假设其他 NoSQL 数据库 API 值得他们的盐)查询数据库的方法比 SQL 简单得多.无需生成繁琐的 SQL 查询等.例如从 mongodb-csharp:

with MongoDB (and I assume other NoSQL database APIs worth their salt) the ways of querying the database are much more simplistic than SQL. There is no tedious SQL queries to generate and such. For instance take this from mongodb-csharp:

using MongoDB.Driver; 
Mongo db = new Mongo(); 
db.Connect(); //Connect to localhost on the default port. 
Document query = new Document(); 
query["field1"] = 10; 
Document result = db["tests"]["reads"].FindOne(query); 
db.Disconnect();

ORM 怎么能简化它呢?在体面的 NoSQL API 之上是否需要 ORM 或其他数据库抽象设备"?

How could an ORM even simplify that? Is an ORM or other "database abstraction device" required on top of a decent NoSQL API?

推荐答案

嗯,是的,对象-关系映射器对于 MongoDB 来说是多余的,因为 MongoDB 不是一个关系数据库,它是一个面向文档的数据库.

Well, yes, Object-Relational mappers are redundant with MongoDB because MongoDB isn't a relational database, it's a Document-Oriented database.

因此,您使用 JSON 编写查询而不是 SQL.除非您真的真的想要编写原始 JSON,而不是 Linq,否则您仍然会想要使用映射器.如果您不想创建与 MongoDB 本身的耦合,那么您不想传递实际的 Document 对象,而是想将它们映射到真正的 POCO.

So instead of SQL, you write queries in JSON. Unless you really, really want to write raw JSON, as opposed to, say, Linq, then you're still going to want to use a mapper. And if you don't want to create coupling against MongoDB itself, then you don't want to pass actual Document objects around, you want to map them to real POCOs.

对于像 MongoDB 这样的面向文档的数据库,映射要更容易,因为您使用的是嵌套文档而不是关系,但这并不意味着它完全消失了.这只是意味着您已将一种类型的阻抗失配"替换为另一种稍微不那么戏剧性的失配.

The mapping is much easier with a document-oriented DB like MongoDB, because you have nested documents instead of relations, but that doesn't mean it goes away completely. It just means you've substituted one type of "impedance mismatch" for a different, slightly-less-dramatic mismatch.

这篇关于带有 NoSQL API 的 ORM 是多余的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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