java orm 开源框架_探索.NET开源混合ORM库RepoDB

java orm 开源框架

java orm 开源框架

Shutterstock

It's nice to explore alternatives, especially in open source software. Just because there's a way, or an "official" way doesn't mean it's the best way.

很高兴探索替代方案,尤其是在开源软件中。 仅仅因为有一种方法或“官方”方法并不意味着这是最好的方法。

Today I'm looking at RepoDb. It says it's "a hybrid ORM library for .NET. It is your best alternative ORM to both Dapper and Entity Framework." Cool, let's take a look.

今天我正在看RepoDb 。 它说它是“ .NET的混合ORM库。它是Dapper和Entity Framework的最佳替代ORM。” 酷,让我们看一看。

Michael Pendon, the author puts his micro-ORM in the same category as Dapper and EF. He says "RepoDb is a new hybrid micro-ORM for .NET designed to cater the missing pieces of both micro-ORMs and macro-ORMs (aka full-ORMs). Both are fast, efficient and easy-to-use. They are also addressing different use-cases."

作者Michael Pendon将其微型ORM与Dapper和EF归为同一类。 他说:“ RepoDb是一种用于.NET的新型混合微型ORM,旨在解决微型ORM和宏ORM(又称完整ORM)缺失的部分。它们都是快速,高效且易于使用的。还解决了不同的用例。”

Dapper is a great and venerable library that is great if you love SQL. Repo is a hybrid ORM and offers more than one way to query, and support a bunch of popular databases:

Dapper是一个很棒且受人尊敬的库,如果您喜欢SQL,那就很棒。 Repo是一种混合ORM,它提供了多种查询方式,并支持许多流行的数据库:

Here's some example code:

这是一些示例代码:

/* Dapper */
using (var connection = new SqlConnection(ConnectionString))
{
var customers = connection.Query<Customer>("SELECT Id, Name, DateOfBirth, CreatedDateUtc FROM [dbo].[Customer];");
}

/* RepoDb - Raw */
using (var connection = new SqlConnection(ConnectionString))
{
var customers = connection.ExecuteQuery<Customer>("SELECT Id, Name, DateOfBirth, CreatedDateUtc FROM [dbo].[Customer];");
}

/* RepoDb - Fluent */
using (var connection = new SqlConnection(ConnectionString))
{
var customers = connection.QueryAll<Customer>();
}

I like RepoDB's strongly typed Fluent insertion syntax:

我喜欢RepoDB的强类型Fluent插入语法:

/* RepoDb - Fluent */
using (var connection = new SqlConnection(connectionString))
{
var id = connection.Insert<Customer, int>(new Customer
{
Name = "John Doe",
DateOfBirth = DateTime.Parse("1970/01/01"),
CreatedDateUtc = DateTime.UtcNow
});
}

Speaking of inserts, it's BulkInsert (my least favorite thing to do) is super clean:

说到插入,BulkInsert(我最不喜欢做的事情)是超级干净的:

using (var connection = new SqlConnection(ConnectionString))
{
var customers = GenerateCustomers(1000);
var insertedRows = connection.BulkInsert(customers);
}

The most interesting part of RepoDB is that it formally acknowledges 2nd layer caches and has a whole section on caching in the excellent RepoDB official documentation. I have a whole LazyCache subsystem behind my podcast site that is super fast but added some complexity to the code with more Func<T> that I would have preferred.

RepoDB最有趣的部分是它正式承认第二层缓存,并且在出色的RepoDB官方文档中有一章完整地介绍了缓存。 我的播客站点后面有一个完整的LazyCache子系统,该子系统非常快,但由于我希望使用更多的Func <T>来增加代码的复杂性

This is super clean, just passing in an ICache when you start the connection and then mention the key when querying.

这非常干净,在启动连接时传入ICache,然后在查询时提及密钥。

var cache = CacheFactory.GetMemoryCache();
using (var connection = new SqlConnection(connectionString).EnsureOpen())
{
var products = connection.QueryAll<Product>(cacheKey: "products", cache: cache);
}

using (var repository = new DbRepository<Product, SqlConnection>(connectionString))
{
var products = repository.QueryAll(cacheKey: "products");
}

It also shows how to do generated cache keys...also clean:

它还显示了如何执行生成的缓存键...也很干净:

// An example of the second cache key convention:
var cache = CacheFactory.GetMemoryCache();
using (var connection = new SqlConnection(connectionString).EnsureOpen())
{
var productId = 5;
Query<Product>(product => product.Id == productId,
cacheKey: $"product-id-{productId}",
cache: cache);
}

And of course, if you like to drop into SQL directly for whatever reason, you can .ExecuteQuery() and call sprocs or use inline SQL as you like. So far I'm enjoying RepoDB very much. It's thoughtfully designed and well documented and fast. Give it a try and see if you like it to?

当然,如果您出于任何原因希望直接加入SQL,可以使用.ExecuteQuery()并调用sproc或根据需要使用内联SQL。 到目前为止,我非常喜欢RepoDB。 经过精心设计,文档完善,快速。 试试看,看是否喜欢?

Why don't you head over to https://github.com/mikependon/RepoDb now and GIVE THEM A STAR. Encourage open source. Try it on your own project and go tweet the author and share your thoughts!

您为什么不现在访问https://github.com/mikependon/RepoDb并给他们一个星星。 鼓励开源。 在您自己的项目上尝试一下,然后在推特上发帖并分享您的想法!

翻译自: https://www.hanselman.com/blog/exploring-the-net-open-source-hybrid-orm-library-repodb

java orm 开源框架

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值