小巧玲珑的列数,而不是列名? [英] Dapper Column number rather than column name?

查看:216
本文介绍了小巧玲珑的列数,而不是列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常类似的问题,以小巧玲珑点网"没有列名&QUOT ; ,但答案没有让我在哪里,我需要

I have a very similar question to Dapper-dot-net "no column name", but the answer there is not getting me where I need.

我正在写一个Web界面,并使用短小精悍得到来自我的客户的ERP系统存储过程数据。该SP返回的数据的4列不列名。话虽这么说SP的被锁定,我不能改变它们。 我试图解决这个通过使用临时表在我的查询作为萨姆建议。

I'm writing a web interface and using dapper to get data from Stored Procedures from my client's ERP system. The SP returns 4 columns of data without column names. That being said the SP's are locked and I can't change them. I've tried to work around this by using a temp table in my query as Sam suggested.

var grid = QueryMultiple(@"set nocount on 
declare @t table(Id int, Name nvarchar(max), AnotherId int)

insert @t
exec proc

set nocount off 
select Id, Name from @t
select Id, AnotherId from @t
");

不过,我现在才发现原来SP还包含一个刀片,日志记录,因此SQL不会让我插入,因为这是我的SP到一个临时表。

However, I've now discovered the original SP also contains an insert for logging and therefore SQL will not allow me to insert my sp into a temp table because of this.

有提及增加了对支持的:

There is mention of adding support for:

class Foo { [ColumnNumber(1)] public string Name {get;set;} }

我怎样才能做到这一点?有人点我在正确的方向修改小巧玲珑源不要求列名,并允许我列号映射?

How can I do this? Can someone point me in the right direction to modify Dapper source to not require column names and allow me to map by column number?

推荐答案

不平凡的绑定问题不断上来;它想出了最近,大多数在这里: HTTP:/ /$c$c.google.com/p/dapper-dot-net/issues/detail?id=108

The issue of non-trivial bindings keeps coming up; it came up most recently here: http://code.google.com/p/dapper-dot-net/issues/detail?id=108

我的建议也表示,虽然我还没有来得及code呢。我提出了一个静态事件,你可以选择处理,并适用于任何深奥的映射你想要的,即

My suggestion there stands, although I haven't had time to code it yet. I propose a static event that you can choose to handle, and apply whatever esoteric mappings you want, i.e.

SqlMapper.ColumnBind += (sender, args) {
    int colIndex = args.ColumnIndex;
    Type type = args.TargetType;
    MemberInfo member = // ... Entirely up to you to define logic
    args.Member = member;
};

以上完全是理论性的,但它会满足您的需求?

The above is entirely theoretical, but would it meet your needs?

请注意:如果 Col​​umnBind 没有订阅,它只是做普通的基本名称映射为正常。思考?

Note: if ColumnBind was not subscribed, it would just do normal basic name mapping as normal. Thoughts?

(注:也有可能是每个类型的单个事件调用,而不是每列;这可能更有效,因为用户会调用的GetProperties,等少常)

(note: it could also be a single event invoke per type, rather than per-column; that might be more efficient, as the subscriber will call GetProperties etc less often)

这篇关于小巧玲珑的列数,而不是列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆