Skip to content

Commit 5424f6f

Browse files
committed
Merge remote branches 'firo222/master' and 'briandonahue/master'
3 parents 02063a4 + 2b95151 + 7c79f7c commit 5424f6f

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

src/FluentNHibernate.Testing/DomainModel/Mapping/ClassMapXmlCreationTester.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ public class ChildObject
582582
public virtual int Id { get; set; }
583583
public virtual string Name { get; set; }
584584
public virtual int Position { get; set; }
585+
public virtual bool Active { get; set; }
585586
}
586587

587588
public class MappedGenericObject<T>

src/FluentNHibernate.Testing/ExpressionToSqlTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@ public void ConvertEqualsPropertyAndString()
5555
sql.ShouldEqual("Name = '1'");
5656
}
5757

58+
[Test]
59+
public void ConvertEqualsPropertyAndTrue()
60+
{
61+
var sql = ExpressionToSql.Convert<ChildObject>(x => x.Active == true);
62+
63+
sql.ShouldEqual("Active = 1");
64+
}
65+
66+
[Test]
67+
public void ConvertEqualsPropertyAndFalse()
68+
{
69+
var sql = ExpressionToSql.Convert<ChildObject>(x => x.Active == false);
70+
71+
sql.ShouldEqual("Active = 0");
72+
}
73+
74+
[Test]
75+
public void ConvertBooleanPropertyImplicitTrue()
76+
{
77+
var sql = ExpressionToSql.Convert<ChildObject>(x => x.Active);
78+
79+
sql.ShouldEqual("Active = 1");
80+
}
81+
82+
[Test]
83+
public void ConvertBooleanPropertyImplicitFalse()
84+
{
85+
var sql = ExpressionToSql.Convert<ChildObject>(x => !x.Active);
86+
87+
sql.ShouldEqual("Active = 0");
88+
}
89+
5890
[Test]
5991
public void ConvertGreater()
6092
{

src/FluentNHibernate/Mapping/VersionPart.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class VersionPart : IVersionMappingProvider
1212
private readonly Type entity;
1313
private readonly Member property;
1414
private readonly AccessStrategyBuilder<VersionPart> access;
15-
private readonly VersionGeneratedBuilder<IVersionMappingProvider> generated;
15+
private readonly VersionGeneratedBuilder<VersionPart> generated;
1616
private readonly AttributeStore<VersionMapping> attributes = new AttributeStore<VersionMapping>();
1717
private readonly AttributeStore<ColumnMapping> columnAttributes = new AttributeStore<ColumnMapping>();
1818
private readonly List<string> columns = new List<string>();
@@ -23,13 +23,13 @@ public VersionPart(Type entity, Member property)
2323
this.entity = entity;
2424
this.property = property;
2525
access = new AccessStrategyBuilder<VersionPart>(this, value => attributes.Set(x => x.Access, value));
26-
generated = new VersionGeneratedBuilder<IVersionMappingProvider>(this, value => attributes.Set(x => x.Generated, value));
26+
generated = new VersionGeneratedBuilder<VersionPart>(this, value => attributes.Set(x => x.Generated, value));
2727
}
2828

2929
/// <summary>
3030
/// Specify if this version is database generated
3131
/// </summary>
32-
public VersionGeneratedBuilder<IVersionMappingProvider> Generated
32+
public VersionGeneratedBuilder<VersionPart> Generated
3333
{
3434
get { return generated; }
3535
}

src/FluentNHibernate/Utils/ExpressionToSql.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public static string Convert<T>(Expression<Func<T, bool>> expression)
3232
{
3333
if (expression.Body is BinaryExpression)
3434
return Convert<T>((BinaryExpression)expression.Body);
35+
var memberExpression = expression.Body as MemberExpression;
36+
if (memberExpression != null && memberExpression.Type == typeof(bool))
37+
return Convert(CreateExpression<T>(memberExpression)) + " = " + Convert(true);
38+
var unaryExpression = expression.Body as UnaryExpression;
39+
if (unaryExpression != null && unaryExpression.Type == typeof(bool) && unaryExpression.NodeType == ExpressionType.Not)
40+
return Convert(CreateExpression<T>(unaryExpression.Operand)) + " = " + Convert(false);
41+
42+
3543

3644
throw new NotImplementedException();
3745
}
@@ -135,6 +143,10 @@ private static string Convert(object value)
135143
{
136144
if (value is string)
137145
return "'" + value + "'";
146+
if (value is bool)
147+
{
148+
return (bool)value ? "1" : "0";
149+
}
138150

139151
return value.ToString();
140152
}

0 commit comments

Comments
 (0)