Nicholas Piasecki wrote:
Hi all,
I'm having a bizarre problem with the QueryForDictionary<T,T2> method.
Specifically, the "keyProperty" parameter to the method.
I have a "Product" object with a "Sku" property that I would like to
use as a key. If I specify "Sku" as the keyProperty, I get a
"ProbeException" saying that "There is no Get member named 'Sku' in
class 'Object'".
What's weird is that if I specify a keyProperty that does not exist in
"Product", such as "SkuNotReallyAProperty", I get a "ProbeException"
saying that "There is no Get member named 'SkuNotReallyAProperty' in
class 'Product'".
It seems odd that when I specify a property that doesn't exist, the
ObjectProbe is searching the correct type ("Product"), but when I
specify a property that DOES exist, the ObjectProbe is searching the
wrong type ("Object").
I've even tried using other properties as keys, ("Name",
"Description", etc, which are all valid properties on the "Product"
type) but still no joy. When using QueryForList<> on this same select
statement, it works fine.
This is using DataMapper 1.6.1. Here's the invocation (search is just
a string):
products =
LocalSqlMap.QueryForDictionary<Sku, Product>(
"Product.GetProductsByManufacturerId", search +
"%", "Sku");
Here's the line from the products data mapper:
<select
id="GetProductsByManufacturerId"
parameterClass="string"
resultMap="ResultMapProduct">
SELECT
<include refid="FragmentSelectProduct" />
WHERE p.Active = 'Y'
AND p.TheirId LIKE #value#
ORDER BY p.SalesVolume DESC, p.DateAdded DESC
</select>
Finally, here's a snippet from ResultMapProduct:
<resultMap
id="ResultMapProduct"
class="Product"
groupBy="Sku">
<result
column="ProductSku"
property="Sku" />
<!-- Stripped out miscellaneous other result mappings -->
</resultMap>
What am I doing wrong? Thanks for any insight!
V/R,
Nicholas Piasecki
A follow up to my own question:
Apparently, the QueryForDictionary<T,T2> method has problems with the
"groupBy" on my ResultMapProduct. (This query does a LEFT OUTER JOIN to
pull down fabric swatches for a particular product to avoid the N+1
select problem.) I didn't have to remove the "groupBy" attribute to fix
the problem, just the LEFT OUTER JOIN that pulls in the fabric switches
and causes the same product to appear multiple times in the result set.
In the result map, the swatches are specified as
<result
property="Swatches"
resultMapping="Product.ResultMapSwatch" />
Before (with the join) the result set looked something like this (with
groupBy set to "Sku"):
Sku, Swatch
1008615, Gray
1008615, White
1008615, Black
2059824, NULL
2033614, Contrast
In a QueryByList<Product> call, there are 3 results, and the product
with Sku 1008615 has three fabric swatches in its Swatches collection.
That's what I want, but it bombs in QueryForDictionary with the
ProbeException.
After I removed the join, the result set looks something like this and
QueryForDictionary succeeds:
1008615, NULL
2059824, NULL
2033614, NULL
I don't need the swatches for this query, so this workaround is fine.
But it seems odd that this "groupBy" behavior would work fine for
QueryForList<T> but fail for QueryForDictionary<T,T2>. Anyone know if
this is a limitation of the QueryForDictionary<T,T2> method, or if I
just missed this is in the documentation somewhere?
Thanks!
V/R,
Nicholas Piasecki