Uploaded image for project: 'iBatis for .NET'
  1. iBatis for .NET
  2. IBATISNET-283

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

    XMLWordPrintableJSON

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

      Attachments

        Activity

          People

            gilles Gilles Bayon
            rbanks54 Richard Banks
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: