Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding dynamic-component

  • Loading branch information...
commit f837a95277564f80f86bc9be438966c58af39709 1 parent d48a0f9
Ayende Rahien authored

Showing 3 changed files with 19 additions and 4 deletions. Show diff stats Hide diff stats

  1. +3 2 Model/Student.cs
  2. +6 0 Model/Student.hbm.xml
  3. +10 2 Program.cs
5 Model/Student.cs
... ... @@ -1,4 +1,5 @@
1   -using System.Collections.Generic;
  1 +using System.Collections;
  2 +using System.Collections.Generic;
2 3
3 4 namespace NHibernateCourse.QuickStart.Model
4 5 {
@@ -8,7 +9,7 @@ public class Student
8 9 public virtual string Name { get; set; }
9 10
10 11 public virtual int Age { get; set; }
11   -
  12 + public virtual IDictionary Attributes { get; set; }
12 13 public virtual bool IsBuly { get; set; }
13 14
14 15 public virtual ICollection<Test> Tests { get; set; }
6 Model/Student.hbm.xml
@@ -18,6 +18,12 @@
18 18 <property name="Street"/>
19 19 <property name="HouseNumber"/>
20 20 </component>
  21 +
  22 + <dynamic-component name="Attributes">
  23 + <property name="GPA4" type="System.String"/>
  24 + <property name="GPA5" type="System.Int32"/>
  25 + </dynamic-component>
  26 +
21 27 <list name="EmergencyPhones" table="EmergencyPhone">
22 28 <key column="StudentId" />
23 29 <index column="Position"/>
12 Program.cs
... ... @@ -1,4 +1,5 @@
1 1 using System;
  2 +using System.Collections;
2 3 using System.Collections.Generic;
3 4 using System.Diagnostics;
4 5 using System.Linq;
@@ -48,7 +49,12 @@ private static void Action(ISessionFactory sessionFactory)
48 49 Street = "Electro Way"
49 50 },
50 51 Age = 15,
51   - Name = "Frank"
  52 + Name = "Frank",
  53 + Attributes = new Hashtable
  54 + {
  55 + {"GPA4", "abc"},
  56 + {"GPA5", 32}
  57 + }
52 58 });
53 59
54 60
@@ -59,7 +65,9 @@ private static void Action(ISessionFactory sessionFactory)
59 65 using (var session = sessionFactory.OpenSession())
60 66 using (var tx = session.BeginTransaction())
61 67 {
62   - Console.WriteLine(session.Get<Student>(1).Address.City);
  68 + session.CreateCriteria<Student>()
  69 + .Add(Restrictions.Eq("Attributes.GPA4", "abc"))
  70 + .List();
63 71
64 72 tx.Commit();
65 73 }

0 comments on commit f837a95

Please sign in to comment.
Something went wrong with that request. Please try again.