code_junkie

NHibernate with string primary key and relationships

Nov 13th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. return session.Get<T>(id);
  2.  
  3. <class name="Merchant" table="T__MERCHANT">
  4. <id name="MerchantId" column="MERCHANT_ID" type="string">
  5. <generator class="assigned" />
  6. </id>
  7.  
  8. <property name="MerchantStatusId" column="MERCHANT_STATUS_ID" type="Char" not-null="true" length="1" />
  9. <property name="MerchantStatusName" column="MERCHANT_STATUS_NAME" type="string" length="50" />
  10. <property name="MerchantName" column="NAME" type="string" not-null="true" length="50" />
  11. </class>
  12. </hibernate-mapping>
  13.  
  14. public Merchant GetMerchantById(string id)
  15. {
  16. return session.Get<Merchant>(id);
  17. }
  18.  
  19. <joined-subclass name="JohnHarmanLtd.Web.FineArtCompany.Models.Book, App_Code.tqeub3fb, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
  20.  
  21. Imports NHibernate.UserTypes
  22. Imports NHibernate.Type
  23. Imports NHibernate.SqlTypes
  24.  
  25. Public Class CaseInsensitiveStringType
  26. Inherits AbstractStringType
  27.  
  28. ' Methods
  29. Public Sub New()
  30. MyBase.New(New StringSqlType)
  31. End Sub
  32.  
  33. Public Sub New(ByVal sqlType As StringSqlType)
  34. MyBase.New(sqlType)
  35. End Sub
  36.  
  37.  
  38. ' Properties
  39. Public Overrides ReadOnly Property Name As String
  40. Get
  41. Return "InsensitiveString"
  42. End Get
  43. End Property
  44.  
  45. Public Overrides Function IsEqual(ByVal x As Object, ByVal y As Object) As Boolean
  46. Return MyBase.IsEqual(x, y) OrElse (x IsNot Nothing AndAlso y IsNot Nothing AndAlso String.Equals(x, y, StringComparison.InvariantCultureIgnoreCase))
  47. End Function
  48.  
  49. Public Overrides Function GetHashCode(ByVal x As Object, ByVal entityMode As NHibernate.EntityMode, ByVal factory As NHibernate.Engine.ISessionFactoryImplementor) As Integer
  50. Return MyBase.GetHashCode(x.ToString().Trim().ToUpperInvariant(), entityMode, factory)
  51. End Function
  52. End Class
  53.  
  54. Id(Function(x) x.Id).GeneratedBy.Assigned().CustomType(Of CaseInsensitiveStringType)()
  55.  
  56. Example.create(parent).ignoreCase()
Add Comment
Please, Sign In to add comment