我使用
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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。