forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchema.cshtml.cs
68 lines (57 loc) · 1.46 KB
/
Schema.cshtml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using NHibernate.Example.Web.Infrastructure;
using NHibernate.Example.Web.Models;
using NHibernate.Tool.hbm2ddl;
namespace NHibernate.Example.Web.Pages
{
public class SchemaModel : PageModel
{
[TempData]
public string Status { get; set; }
private readonly AppSessionFactory _applicationSession;
private readonly ISession _session;
public SchemaModel(ISession session, AppSessionFactory applicationSession)
{
_applicationSession = applicationSession;
_session = session ?? throw new ArgumentNullException(nameof(session));
}
public void OnGet()
{
}
public IActionResult OnPostCreateSchema()
{
var export = new SchemaExport(_applicationSession.Configuration);
export.Create(false, true);
using (var tx = _session.BeginTransaction())
{
var item1 = new Item
{
Description = "First item",
Price = 100m
};
_session.Save(item1);
var item2 = new Item
{
Description = "Second item",
Price = 150m
};
_session.Save(item2);
tx.Commit();
}
Status = "Schema created";
return RedirectToPage();
}
public IActionResult OnPostDropSchema()
{
SchemaExport export = new SchemaExport(_applicationSession.Configuration);
export.Drop(false, true);
Status = "Schema dropped";
return RedirectToPage();
}
}
}