使用 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.
这篇关于ORM 与 NoSQL API 是多余的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!