All work
- Enums in LINQ query do not provide correct values for SQL statement parametersNHLQ-98
- Equals Expression ignores custom methods.NHLQ-92
- Improper handling of lambdas that look like 'x => true' in queriesNHLQ-91
- Contains/StartWith error when using MS SQL SERVER CE (Visual Studio database for developers)NHLQ-90
- NHibernate cuts two last symbols of filter pattern when using IsInsensitiveLike and MatchMode.Anywhere with limited field length in DBNHLQ-89
- Fetch/Cacheable Should Be Called AnyoneNHLQ-88
- "where" after "group by" not workingNHLQ-87
- Properties of Dynamic-Components can't be queriedNHLQ-86
- Last() Not ImplementedNHLQ-85
- Incorrect table alias generated in where clauseNHLQ-83
- NHibernate 3CR1: Fetching strategy poblemsNHLQ-82
- NHibernate 3CR1: Conversion From Linq Query to Sql, generates sql syntax problem of unnecessary bracketsNHLQ-81
- string comparison parameter in the where clause is not being passed into the generated SQL after a previous execution with 'null' as the parameter valueNHLQ-80
- Update to .Net 4.0 causes unit tests to fail with "Extension node must override the property Expression.NodeType."NHLQ-78
- Linq query with some null parameter in where clause is cached wronglyNHLQ-77
- LINQ query does not honour fetch="join" mapping attribute applied to a setNHLQ-76
- Take() doesn't seem to work in nHibernate.linqNHLQ-74
- No implementation for Coalesce Binary ExpressionNHLQ-73
- Linq-to-NHibernate issue with paging and countsNHLQ-72
- sourceforge download brokenNHLQ-71Resolved issue: NHLQ-71Stephen Bohlen
- Take or First does a Limit on all lines when join and not only on primary entitiyNHLQ-70
- LINQ Paging ErrorNHLQ-69
- String compare when using VB.NET throws ArgumentExceptionNHLQ-68
- Passing expressions on nested queries fails..NHLQ-67
- Index was out of range, ToLower() method does not have any argumentsNHLQ-66
- Short-circuiting of boolean operatorsNHLQ-65
- Cannot query components using an expression built around an interfaceNHLQ-64
- SelectMany support without needing to mantain the parameter nameNHLQ-63
- .ToSting() is not supported in SelectNHLQ-62
- Generated sql for addition to another property doesn't consider the other propertyNHLQ-61
- Subselect fetched one-to-many relationship does not generate child SQL that takes into consideration Skip() and Take()NHLQ-60
- Problems with "degenerate" selects when eager fetching using Expand with DistinctRootEntityResultTransformerNHLQ-59
- Count() incorrect when using polymorphic query (mapped table per class hierarchy)NHLQ-58
- using Length in Linq query throws errorNHLQ-57
- where clause returns invalid results that prevent WCF data services from navigation relationshipsNHLQ-56
- ToLower() / ToUpper() in where clause (where stu.Name.ToLower().Contains(nameFragment)) produces opposite SQL clause to expectedNHLQ-55
- problem with var q = NHibernateHelper.GetCurrentSession().Linq<Person>().OrderBy(x => x.LastName ).ThenBy(x=>x.Id).GroupBy(x=>x.LastName).OrderBy(x=>x.Key).Select(x => new object[] { (x.Key), (x.Count()) } );NHLQ-54
- Expression translation doesn't handle components properlyNHLQ-53
- Joins become LEFT OUTER JOIN by default. Should be LEFT JOIN. Or: Implement DefaultIfEmpty()NHLQ-52
- WhereArgumentsVisitor does not take proxied entities into accountNHLQ-51Resolved issue: NHLQ-51Chad Lee
- Support for Get methods for collections (instead of property accessors for collectionsNHLQ-50
- NHibernateContext (ADO.NET Data Services support) bugfixNHLQ-49Resolved issue: NHLQ-49Chad Lee
- "System.ArgumentException: Expression of type 'System.Int32' cannot be used for return type 'System.Boolean'" message when searching for a string matchNHLQ-48
- The SingleResultOperator result operator is not current supportedNHLQ-47
- Where(x => "my constant string".Contains(x.MyProp)) throws System.InvalidOperationException : Expression argument must be of type ICollection.NHLQ-46
- Bitwise Operations with Flagged Enums throw ExceptionNHLQ-45
- InvalidCastException when trying to use a constant in a queryNHLQ-44
- Duplicate alias QueryException thrown when executing a modified linq queryNHLQ-43
- Cannot select the entire instance and some of its properties in projectionsNHLQ-42
- OrderBy(x => x) failingNHLQ-41
50 of 90
Enums in LINQ query do not provide correct values for SQL statement parameters
Description
Environment
None
Created March 11, 2011 at 12:39 PM
Updated March 11, 2011 at 12:39 PM
Activity
Show:
Using enums inside of WHERE criteria produces correct SQL statement, but value is calculated improperly.
In my case I map enum to varchar2 column and use NHibernate.Type.EnumStringType class to handle value mapping. When an object with enum property is saved, the value sent to GetValue() method is of enum type. But when LINQ query is executed the value passed to GetValue() method is not an enum but an integer.
To handle this issue I used additional piece of code if value is of int type -
public enum Formula {
fNone,
fRatio,
fXXX
}
public class Formula_Map : NHibernate.Type.EnumStringType {
public Formula_Map() : base(typeof(Formula)) {}
public override object GetInstance(object code) {
try {
switch(code as string) {
case "None": return Formula.fNone;
case "Ratio": return Formula.fRatio;
case "XXX": return Formula.fXXX;
}
return Formula.fNone;
}
catch (ArgumentException ae) {
throw new NHibernate.HibernateException(string.Format("Can not Parse {0} as {1}", code, ReturnedClass.Name), ae);
}
}
public override object GetValue(object code) {
if (code == null)
return "?";
else {
if (Enum.Equals(code, Formula.fNone)) return "None";
if (Enum.Equals(code, Formula.fRatio)) return "Ratio";
if (Enum.Equals(code, Formula.fXXX)) return "XXX";
// — the following code is a workaround to handle situation
// — when the value is an integer, not enum
if (code is int)
{
switch ((int)code)
{
case(0): return "None";
case(1): return "Ratio";
case(2): return "XXX";
}
}
return "??";
}
}
}