iBatis for .NET
  1. iBatis for .NET
  2. IBATISNET-283

Result mappings should work with interfaces when QueryForObject is passed an existing object

    Details

      Description

      In the IBatisNet.DataMapper.DataExchange.DotNetObjectDataExchange class the method public override void SetData(ref object target, ResultProperty mapping, object dataBaseValue)
      does a check against types using this statement:

      if ((type != this._parameterClass) && !type.IsSubclassOf(this._parameterClass))

      The problem here is that IsSubclassOf doesn't check for interface implementations. When _parameterClass is an interface you also need to check using

      type.GetInterfaces().Contains(this._parameterClass)

      This would then allow for result mappings to use interfaces, which is really useful when you are using an IoC container to instantiate the class being populated, for example:

      ISale sale = Container.Resolve<ISale>();
      ...
      Mapper.Instance().QueryForObject<ISale>("uspSelectSale", saleNumber, sale);

      Thanks

        Activity

        Gilles Bayon made changes -
        Fix Version/s DataMapper 1.6.2 [ 12312374 ]
        Fix Version/s DataMapper 3.0 [ 11044 ]
        Status In Progress [ 3 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Hide
        Gilles Bayon added a comment -

        in SVN

        Show
        Gilles Bayon added a comment - in SVN
        Gilles Bayon made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Gilles Bayon made changes -
        Field Original Value New Value
        Assignee Gilles Bayon [ gilles ]
        Hide
        Richard Banks added a comment -

        Doh! I forgot - you can just use the C# is operator. It'll be a lot easier to read

        Show
        Richard Banks added a comment - Doh! I forgot - you can just use the C# is operator. It'll be a lot easier to read
        Richard Banks created issue -

          People

          • Assignee:
            Gilles Bayon
            Reporter:
            Richard Banks
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development