c# – Insight.Database列映射到对象
发布时间:2020-12-15 22:36:23 所属栏目:百科 来源:网络整理
导读:我使用 Insight.Database 作为我们的微型ORM.我想弄清楚是否有办法采用以下POCO类关联并将单行结果映射到这些对象中. public class Rule{ public int Id { get; set; } public string Name { get; set; } public RuleDetail Source { get; set; } public Rul
我使用
Insight.Database 作为我们的微型ORM.我想弄清楚是否有办法采用以下POCO类关联并将单行结果映射到这些对象中.
public class Rule { public int Id { get; set; } public string Name { get; set; } public RuleDetail Source { get; set; } public RuleDetail Destination { get; set; } } public class RuleDetail { public int Id { get; set; } public Name { get; set; } public Date DateTime { get; set; } // omitted... } 这是从我们的存储过程返回的列: Id Name // Should map to Source object. SourceId SourceName SourceDateTime // Should map to Destination object. DestinationId DestinationName DestinationDateTime 解决方法
这可以通过查询端的一些设置来实现.不确定属性是否可行.
var returns = Query.Returns( new OneToOne<Rule,RuleDetail,RuleDetail>( callback: (rule,source,destination) => { rule.Source = source; rule.Destination = destination; },columnOverride: new ColumnOverride[] { new ColumnOverride<RuleDetail>("SourceId","Id"),new ColumnOverride<RuleDetail>("SourceName","Name"),new ColumnOverride<RuleDetail>("SourceDateTime","DateTime"),new ColumnOverride<RuleDetail>("DestinationId",new ColumnOverride<RuleDetail>("DestinationName",new ColumnOverride<RuleDetail>("DestinationDateTime",},splitColumns: new Dictionary<Type,string>() { { typeof(Rule),"Id" },{ typeof(RuleDetail),"SourceId" },"DestinationId" },} ) ); return Db.Query(procedure,params,returns); 我不确定是否需要所有代码来使其工作,但它肯定显示了Insight.Database中的查询功能有多强大. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |