Dapper在POCO中是否支持c#6只读属性? [英] Does Dapper support c# 6 read-only properties in POCOs?
本文介绍了Dapper在POCO中是否支持c#6只读属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下内容:
public class SomePoco {
public int IntValue { get; }
}
和
CREATE TABLE SomePocoStorage (IntValue INT NOT NULL)
和
INSERT SomePocoStorage VALUES (1), (274)
如果我打电话
connection.Query<SomePoco>("SELECT * FROM SomePocoStorage")
Dapper句柄是否填充了 IntValue
返回的 SomePoco
实例上的字段?
does Dapper handle populating the IntValue
field on the returned SomePoco
instances?
推荐答案
好问题!我所针对的并不是这种情况,但我很乐意了解其中涉及的内容。由于我们已经做了很多令人讨厌的反思,所以这仍然可行。作为github问题可能更好,但我来看一下。
Good question! It isn't a scenario I've targeted, but I'd be more than happy to take a look at what would be involved. Since we already do a lot of nasty reflection, this could still be viable. Probably better as a github issue, but I'll have a look.
更新- 它现在已经 (当前,仅通过repo-未部署):
Update - it does now (at the current time, via repo only - not deployed):
[Fact] // passes
public void GetOnlyProperties()
{
var obj = connection.QuerySingle<HazGetOnly>(
"select 42 as [Id], 'def' as [Name];");
obj.Id.IsEqualTo(42);
obj.Name.IsEqualTo("def");
}
class HazGetOnly
{
public int Id { get; }
public string Name { get; } = "abc";
}
这篇关于Dapper在POCO中是否支持c#6只读属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文