Skip to content

Commit 660a35c

Browse files
Merge branch 'master' into TypedValue
2 parents 315c79c + f9f0389 commit 660a35c

File tree

134 files changed

+3246
-342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+3246
-342
lines changed

build-common/NHibernate.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<AssemblyVersion>$(VersionMajor).$(VersionMinor).0.0</AssemblyVersion>
1111
<FileVersion>$(VersionPrefix).0</FileVersion>
1212

13+
<NhAppTargetFrameworks>net461;netcoreapp2.0</NhAppTargetFrameworks>
14+
<NhLibTargetFrameworks>net461;netcoreapp2.0;netstandard2.0</NhLibTargetFrameworks>
15+
1316
<Product>NHibernate</Product>
1417
<Company>NHibernate.info</Company>
1518
<Copyright>Licensed under LGPL.</Copyright>

doc/reference/modules/performance.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,20 @@ int accessLevel = permissions["accounts"]; // Error!]]></programlisting>
235235
<literal>left join fetch</literal> in HQL. This tells NHibernate to fetch
236236
the association eagerly in the first select, using an outer join. In the
237237
<literal>ICriteria</literal> query API, you would use
238-
<literal>SetFetchMode(FetchMode.Join)</literal>.
238+
<literal>Fetch()</literal>.
239239
</para>
240240

241241
<para>
242242
If you ever feel like you wish you could change the fetching strategy used by
243243
<literal>Get()</literal> or <literal>Load()</literal>, simply use a
244244
<literal>ICriteria</literal> query, for example:
245245
</para>
246-
246+
247247
<programlisting><![CDATA[User user = session.CreateCriteria(typeof(User))
248-
.SetFetchMode("Permissions", FetchMode.Join)
248+
.Fetch(SelectMode.Fetch, "Permissions")
249249
.Add( Expression.Eq("Id", userId) )
250250
.UniqueResult<User>();]]></programlisting>
251-
251+
252252
<para>
253253
(This is NHibernate's equivalent of what some <emphasis>ORM</emphasis> solutions call a "fetch plan".)
254254
</para>
@@ -475,7 +475,7 @@ using(var iter = session
475475
<literal>NHibernateUtil.Initialize()</literal> for each collection that will
476476
be needed in the web tier (this call must occur before the session is closed)
477477
or retrieves the collection eagerly using a NHibernate query with a
478-
<literal>FETCH</literal> clause or a <literal>FetchMode.Join</literal> in
478+
<literal>FETCH</literal> clause or a <literal>SelectMode.Fetch</literal> in
479479
<literal>ICriteria</literal>. This is usually easier if you adopt the
480480
<emphasis>Command</emphasis> pattern instead of a <emphasis>Session Facade</emphasis>.
481481
</para>

doc/reference/modules/query_criteria.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ foreach ( IDictionary map in cats )
175175

176176
<para>
177177
You may specify association fetching semantics at runtime using
178-
<literal>SetFetchMode()</literal>.
178+
<literal>Fetch()</literal>.
179179
</para>
180180

181181
<programlisting><![CDATA[var cats = sess.CreateCriteria<Cat>()
182182
.Add( Expression.Like("Name", "Fritz%") )
183-
.SetFetchMode("Mate", FetchMode.Eager)
184-
.SetFetchMode("Kittens", FetchMode.Eager)
183+
.Fetch(SelectMode.Fetch, "Mate")
184+
.Fetch(SelectMode.Fetch, "Kittens")
185185
.List<Cat>();]]></programlisting>
186186

187187
<para>

src/NHibernate.DomainModel/NHibernate.DomainModel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="../../build-common/NHibernate.props" />
33
<PropertyGroup>
44
<Description>The Domain Model used by the Unit Tests.</Description>
5-
<TargetFrameworks>netstandard2.0;net461;netcoreapp2.0</TargetFrameworks>
5+
<TargetFrameworks>$(NhLibTargetFrameworks)</TargetFrameworks>
66
<IsTestProject>true</IsTestProject>
77
<NoWarn>$(NoWarn);3001;3002;3003;3005</NoWarn>
88
</PropertyGroup>

src/NHibernate.Test.VisualBasic/NHibernate.Test.VisualBasic.vbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="../../build-common/NHibernate.props" />
33
<PropertyGroup>
44
<Description>The Visual Basic Unit Tests for NHibernate.</Description>
5-
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
5+
<TargetFrameworks>$(NhAppTargetFrameworks)</TargetFrameworks>
66
<IsTestProject>true</IsTestProject>
77
<NoWarn>$(NoWarn);3001;3002;3003;3005</NoWarn>
88
<OptionExplicit>On</OptionExplicit>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using NUnit.Framework;
13+
using System.CodeDom.Compiler;
14+
using System.Linq;
15+
using Microsoft.CSharp;
16+
using System.Reflection;
17+
using NHibernate.Engine;
18+
using NHibernate.Mapping.ByCode;
19+
using NHibernate.Tool.hbm2ddl;
20+
21+
namespace NHibernate.Test.CfgTest
22+
{
23+
using System.Threading.Tasks;
24+
[TestFixture]
25+
public class LoadMemoryOnlyAssembyTestAsync
26+
{
27+
[Test]
28+
public async Task CompileMappingForDynamicInMemoryAssemblyAsync()
29+
{
30+
const int assemblyGenerateCount = 10;
31+
var code = GenerateCode(assemblyGenerateCount);
32+
var assembly = CompileAssembly(code);
33+
34+
var config = TestConfigurationHelper.GetDefaultConfiguration();
35+
var mapper = new ModelMapper();
36+
mapper.AddMappings(assembly.GetExportedTypes());
37+
config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
38+
39+
Assert.That(config.ClassMappings, Has.Count.EqualTo(assemblyGenerateCount), "Not all virtual assembly mapped");
40+
41+
// Ascertain the mappings are usable.
42+
using (var sf = config.BuildSessionFactory())
43+
{
44+
var se = new SchemaExport(config);
45+
await (se.CreateAsync(false, true));
46+
try
47+
{
48+
using (var s = sf.OpenSession())
49+
using (var tx = s.BeginTransaction())
50+
{
51+
foreach (var entityClass in assembly.GetExportedTypes()
52+
.Where(t => !typeof(IConformistHoldersProvider).IsAssignableFrom(t)))
53+
{
54+
var ctor = entityClass.GetConstructor(Array.Empty<System.Type>());
55+
Assert.That(ctor, Is.Not.Null, $"Default constructor for {entityClass} not found");
56+
var entity = ctor.Invoke(Array.Empty<object>());
57+
await (s.SaveAsync(entity));
58+
}
59+
60+
await (tx.CommitAsync());
61+
}
62+
63+
using (var s = sf.OpenSession())
64+
using (var tx = s.BeginTransaction())
65+
{
66+
var entities = await (s.CreateQuery("from System.Object").ListAsync<object>());
67+
Assert.That(entities, Has.Count.EqualTo(assemblyGenerateCount), "Not all expected entities were persisted");
68+
69+
await (tx.CommitAsync());
70+
}
71+
}
72+
finally
73+
{
74+
TestCase.DropSchema(false, se, (ISessionFactoryImplementor) sf);
75+
}
76+
}
77+
}
78+
79+
private static string[] GenerateCode(int assemblyCount)
80+
{
81+
const string codeTemplate = @"
82+
using NHibernate.Mapping.ByCode.Conformist;
83+
84+
public class Entity$$INDEX$$
85+
{
86+
public virtual int ID { get; set; }
87+
public virtual string Name { get; set; }
88+
}
89+
90+
public class Entity$$INDEX$$Map : ClassMapping<Entity$$INDEX$$>
91+
{
92+
public Entity$$INDEX$$Map ()
93+
{
94+
Table(""Entity$$INDEX$$"");
95+
96+
Id(x => x.ID, m =>
97+
{
98+
m.Column(""`ID`"");
99+
});
100+
101+
Property(x => x.Name, m =>
102+
{
103+
m.Column(""`Name`"");
104+
});
105+
}
106+
}";
107+
var code = new string[assemblyCount];
108+
for (var i = 0; i < code.Length; i++)
109+
code[i] = codeTemplate.Replace("$$INDEX$$", i.ToString("000"));
110+
return code;
111+
}
112+
113+
private static Assembly CompileAssembly(string[] code)
114+
{
115+
var parameters = new CompilerParameters
116+
{
117+
GenerateInMemory = true,
118+
TreatWarningsAsErrors = false,
119+
GenerateExecutable = false,
120+
CompilerOptions = "/optimize"
121+
};
122+
parameters.ReferencedAssemblies.AddRange(
123+
new[]
124+
{
125+
"System.dll",
126+
"System.Core.dll",
127+
"System.Data.dll",
128+
new Uri(typeof(Cfg.Environment).Assembly.EscapedCodeBase).LocalPath
129+
});
130+
131+
try
132+
{
133+
using (var provider = new CSharpCodeProvider())
134+
{
135+
var compile = provider.CompileAssemblyFromSource(parameters, code);
136+
137+
if (compile.Errors.HasErrors)
138+
{
139+
var text = "Compile error: " +
140+
string.Join(System.Environment.NewLine, compile.Errors.Cast<CompilerError>());
141+
142+
Assert.Fail(text);
143+
}
144+
145+
return compile.CompiledAssembly;
146+
}
147+
}
148+
catch (PlatformNotSupportedException e)
149+
{
150+
Assert.Inconclusive(e.Message);
151+
return null;
152+
}
153+
}
154+
}
155+
}

src/NHibernate.Test/Async/Criteria/CriteriaQueryTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public async Task ProjectionsTestAsync()
10891089

10901090
object g = await (s.CreateCriteria(typeof(Student))
10911091
.Add(Expression.IdEq(667L))
1092-
.SetFetchMode("enrolments", FetchMode.Join)
1092+
.Fetch("enrolments")
10931093
//.setFetchMode("enrolments.course", FetchMode.JOIN) //TODO: would love to make that work...
10941094
.UniqueResultAsync());
10951095
Assert.AreSame(gavin, g);
@@ -1279,7 +1279,7 @@ public async Task CloningProjectionsTestAsync()
12791279

12801280
ICriteria criteriaToClone6 = s.CreateCriteria(typeof(Student))
12811281
.Add(Expression.IdEq(667L))
1282-
.SetFetchMode("enrolments", FetchMode.Join);
1282+
.Fetch("enrolments");
12831283
object g = await (CriteriaTransformer.Clone(criteriaToClone6)
12841284
.UniqueResultAsync());
12851285
Assert.AreSame(gavin, g);
@@ -2426,7 +2426,7 @@ public async Task SubcriteriaJoinTypesAsync()
24262426
}
24272427

24282428
result = await (session.CreateCriteria(typeof(Student))
2429-
.SetFetchMode("PreferredCourse", FetchMode.Join)
2429+
.Fetch("PreferredCourse")
24302430
.CreateCriteria("PreferredCourse", JoinType.LeftOuterJoin)
24312431
.AddOrder(Order.Asc("CourseCode"))
24322432
.ListAsync());
@@ -2436,7 +2436,7 @@ public async Task SubcriteriaJoinTypesAsync()
24362436
Assert.IsNotNull(result[2]);
24372437

24382438
result = await (session.CreateCriteria(typeof(Student))
2439-
.SetFetchMode("PreferredCourse", FetchMode.Join)
2439+
.Fetch("PreferredCourse")
24402440
.CreateAlias("PreferredCourse", "pc", JoinType.LeftOuterJoin)
24412441
.AddOrder(Order.Asc("pc.CourseCode"))
24422442
.ListAsync());

src/NHibernate.Test/Async/Criteria/EntityProjectionsTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ public async Task EntityProjectionAsSelectExpressionAsync()
228228
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
229229
}
230230
}
231+
232+
[Test]
233+
public async Task EntityProjectionAsSelectExpressionForArgumentAliasAsync()
234+
{
235+
using (var sqlLog = new SqlLogSpy())
236+
using (var session = OpenSession())
237+
{
238+
EntitySimpleChild child1 = null;
239+
var complex = await (session
240+
.QueryOver<EntityComplex>()
241+
.JoinAlias(ep => ep.Child1, () => child1)
242+
.Select(ec => ec.AsEntity())
243+
.Take(1).SingleOrDefaultAsync());
244+
245+
Assert.That(complex, Is.Not.Null);
246+
Assert.That(NHibernateUtil.IsInitialized(complex), Is.True, "Object must be initialized");
247+
Assert.That(NHibernateUtil.IsInitialized(complex.Child1), Is.False, "Object must be lazy");
248+
Assert.That(sqlLog.Appender.GetEvents().Length, Is.EqualTo(1), "Only one SQL select is expected");
249+
}
250+
}
231251

232252
[Test]
233253
public async Task EntityProjectionLockModeAsync()

src/NHibernate.Test/Async/Criteria/Lambda/IntegrationFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public async Task OverrideEagerJoinAsync()
290290
{
291291
var persons =
292292
await (s.QueryOver<Parent>()
293-
.Fetch(p => p.Children).Lazy
293+
.Fetch(SelectMode.Skip, p => p.Children)
294294
.ListAsync());
295295

296296
Assert.That(persons.Count, Is.EqualTo(1));

0 commit comments

Comments
 (0)