Dapper Column number rather than column name?

后端 未结 1 479
情深已故
情深已故 2020-12-18 08:18

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

I\'m writing a web interface and us

相关标签:
1条回答
  • 2020-12-18 08:56

    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

    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?

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

    (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)

    0 讨论(0)
提交回复
热议问题