sapiens / SqlFu

Fast and versatile .net core data mapper/micro-orm
Other
229 stars 50 forks source link

Multi Poco mapping - nullable and guid types not mapped #7

Closed Maarten88 closed 12 years ago

Maarten88 commented 12 years ago

I like SqlFu a lot, and recently started to use the multi-poco mapping feature.

I have created a ViewModel, containing several Entities, and a large query that aliases fields as required. Works perfectly, however, it seems all Nullable fields and Guids in my Entity objects come back empty from the query.

It seems those fields are not mapped. I debugged a little bit, and think the problem is in line 55 of DefaultComplexTypeMapper.cs:

   if (Type.GetTypeCode(p.PropertyType) == TypeCode.Object) return null.

if i change this line to:

   if (Type.GetTypeCode(p.PropertyType) == TypeCode.Object && Nullable.GetUnderlyingType(p.PropertyType) == null && p.PropertyType != typeof(Guid)) // allow nullable types and guids to be mapped
            return null;

then my problem is solved. But I'm not really sure this is the best possible fix, there sure is more to this. Maybe you can look into this?

sapiens commented 12 years ago

I'll take a look ASAP.

sapiens commented 12 years ago

Ok, I think the problem should be solved now. Thank you for providing the fix.