Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added nhibernate paging methods and asp.net core samples
- Loading branch information
Showing
17 changed files
with
494 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
DotNetPaging/DotNetPaging.AspNetCore/Controllers/NHibernateController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using DotNetPaging.NHibernate; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NHibernate; | ||
|
||
namespace DotNetPaging.AspNetCore.Controllers | ||
{ | ||
public class NHibernateController : Controller | ||
{ | ||
private readonly ISession _nhibernateSession; | ||
|
||
public NHibernateController(ISession nhibernateSession) | ||
{ | ||
_nhibernateSession = nhibernateSession; | ||
} | ||
|
||
public async Task<IActionResult> Index(int page = 1) | ||
{ | ||
var releases = await _nhibernateSession.Query<PressRelease>() | ||
.OrderByDescending(p => p.ReleaseDate) | ||
.GetPagedAsync(page, 10); | ||
return View(releases); | ||
} | ||
|
||
public async Task<IActionResult> ICriteria(int page = 1) | ||
{ | ||
var releases = await _nhibernateSession.CreateCriteria<PressRelease>() | ||
.GetPagedAsync<PressRelease>(page, 10); | ||
|
||
return View(releases); | ||
} | ||
|
||
public async Task<IActionResult> QueryOver(int page = 1) | ||
{ | ||
var releases = await _nhibernateSession.QueryOver<PressRelease>() | ||
.GetPagedAsync<PressRelease>(page, 10); | ||
|
||
return View(releases); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
DotNetPaging/DotNetPaging.AspNetCore/Views/NHibernate/ICriteria.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@model PagedResult<DotNetPaging.NHibernate.PressRelease> | ||
@{ | ||
ViewData["Title"] = "Home"; | ||
} | ||
|
||
<h2>NHibernate ICriteria</h2> | ||
|
||
<p>Results on this page are queried using asynchronous method calls of NHibernate.</p> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Company</th> | ||
<th>Title</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var release in Model.Results) | ||
{ | ||
<tr> | ||
<td>@release.ReleaseDate.ToShortDateString()</td> | ||
<td>@release.Company</td> | ||
<td>@release.Title</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
@(await Component.InvokeAsync<PagerViewComponent>(Model)) |
30 changes: 30 additions & 0 deletions
30
DotNetPaging/DotNetPaging.AspNetCore/Views/NHibernate/Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@model PagedResult<DotNetPaging.NHibernate.PressRelease> | ||
@{ | ||
ViewData["Title"] = "Home"; | ||
} | ||
|
||
<h2>NHibernate LINQ</h2> | ||
|
||
<p>Results on this page are queried using asynchronous method calls of NHibernate.</p> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Company</th> | ||
<th>Title</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var release in Model.Results) | ||
{ | ||
<tr> | ||
<td>@release.ReleaseDate.ToShortDateString()</td> | ||
<td>@release.Company</td> | ||
<td>@release.Title</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
@(await Component.InvokeAsync<PagerViewComponent>(Model)) |
30 changes: 30 additions & 0 deletions
30
DotNetPaging/DotNetPaging.AspNetCore/Views/NHibernate/QueryOver.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@model PagedResult<DotNetPaging.NHibernate.PressRelease> | ||
@{ | ||
ViewData["Title"] = "Home"; | ||
} | ||
|
||
<h2>NHibernate QueryOver</h2> | ||
|
||
<p>Results on this page are queried using asynchronous method calls of NHibernate.</p> | ||
|
||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Company</th> | ||
<th>Title</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var release in Model.Results) | ||
{ | ||
<tr> | ||
<td>@release.ReleaseDate.ToShortDateString()</td> | ||
<td>@release.Company</td> | ||
<td>@release.Title</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
|
||
@(await Component.InvokeAsync<PagerViewComponent>(Model)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
DotNetPaging/DotNetPaging.NHibernate/DotNetPaging.NHibernate.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoMapper" Version="8.1.0" /> | ||
<PackageReference Include="NHibernate" Version="5.2.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DotNetPaging.Infrastructure\DotNetPaging.Infrastructure.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions"> | ||
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.dependencyinjection.abstractions\2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
36 changes: 36 additions & 0 deletions
36
DotNetPaging/DotNetPaging.NHibernate/NHibernateExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NHibernate.Cfg; | ||
using NHibernate.Dialect; | ||
using NHibernate.Mapping.ByCode; | ||
|
||
namespace DotNetPaging | ||
{ | ||
public static class NHibernateExtensions | ||
{ | ||
public static IServiceCollection AddNHibernate(this IServiceCollection services, string connectionString) | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.AddMappings(typeof(NHibernateExtensions).Assembly.ExportedTypes); | ||
var domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
|
||
var configuration = new Configuration(); | ||
configuration.DataBaseIntegration(c => | ||
{ | ||
c.Dialect<MsSql2012Dialect>(); | ||
c.ConnectionString = connectionString; | ||
c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote; | ||
c.SchemaAction = SchemaAutoAction.Validate; | ||
c.LogFormattedSql = true; | ||
c.LogSqlInConsole = true; | ||
}); | ||
configuration.AddMapping(domainMapping); | ||
|
||
var sessionFactory = configuration.BuildSessionFactory(); | ||
|
||
services.AddScoped(factory => sessionFactory.OpenSession()); | ||
|
||
return services; | ||
} | ||
} | ||
} |
Oops, something went wrong.