Hello,
I have the following query:
(from i in
Session.Query<ImportFactoryData>()
where i.ImportType == importType
&&
i.ObjectSetName ==
dataSet
select i)
.Fetch(i => i.Downloader)
.SingleOrDefault();
where ImportType is an enum mapped to a custom type. However the
resulting query is:
select importfact0_.Id as Id4_0_,
httpdownlo1_.Id as Id3_1_,
...
importfact0_.ImportType as ImportType4_0_,
...
httpdownlo1_.Uri as Uri3_1_,
...
rom [ImportFactoryData] importfact0_
left outer join [HttpDownload] httpdownlo1_
on importfact0_.Downloader_id = httpdownlo1_.Id
where importfact0_.ImportType = '1'
and importfact0_.ObjectSetName = 'dist_03'
Note that the enum stores and loads just fine. Only the where clause
does not use the custom type. The workaround of course is easy but
somewhat annoying:
(from i in
Session.Query<ImportFactoryData>()
where i.ImportType.ToString() ==
importType.ToString() &&
i.ObjectSetName == dataSet
select i)
.Fetch(i => i.Downloader)
.SingleOrDefault();
Am I missing something? Maybe my custom type is not OK...?
public class EnumMapper<T> : IUserType where T : struct
{
public EnumMapper()
{
if (!typeof(T).IsEnum)
throw new ArgumentException("The generic parameter of
'EnumMapper<>' must be an enum type.");
}
public bool IsMutable
{
get { return true; }
}
public Type ReturnedType
{
get { return typeof(T); }
}
public SqlType[] SqlTypes
{
get { return new SqlType[] { new
AnsiStringFixedLengthSqlType(32) }; }
}
public object Assemble(object cached, object owner)
{
return DeepCopy(cached);
}
public object DeepCopy(object value)
{
if (value!=null)
return (T)value;
else
return null;
}
public object Disassemble(object value)
{
return DeepCopy(value);
}
public new bool Equals(object x, object y)
{
if (x==null)
return y==null;
if (y==null)
return false;
return object.Equals((T)x, (T)y);
}
public int GetHashCode(object x)
{
if (x==null)
return 0;
return x.GetHashCode();
}
public object NullSafeGet(IDataReader rs, string[] names,
object owner)
{
if (rs == null)
throw new ArgumentNullException("rs");
if (names == null)
return null;
if (names.Length < 1)
return null;
int i = rs.GetOrdinal(names[0]);
if (rs.IsDBNull(i))
return null;
string s = rs.GetString(i);
if (string.IsNullOrWhiteSpace(s))
return null;
return Enum.Parse(typeof(T), s.Trim(), true);
}
public void NullSafeSet(System.Data.IDbCommand cmd, object
value, int index)
{
if (cmd == null)
throw new ArgumentNullException("cmd");
if (value==null)
((IDbDataParameter)cmd.Parameters[index]).Value =
DBNull.Value;
else
((IDbDataParameter)cmd.Parameters[index]).Value =
value.ToString();
}
public object Replace(object original, object target, object
owner)
{
if (original==null)
return null;
else
return (T)original;
}
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.