Does anyone know how the object can be made so that it does have something in its identity field – so that i can then use this to get the hash code.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One option is to use Guid as id. This way you don’t need database round trip to get identity value.
Or
‘PersonId’ column type should be uniqueidentifier if you use SQL Server. Then when you create object you can use Guid.NewGuid() to generate new id.
The advantage of this approach is that your code is more decoupled from database. This will be very helpful during tests and if you need to support ‘disconnected’ scenarios. Potential disadvantage is the performance during joins (google “guid vs int primary key”). See this for additional information on id generators in NHibernate.
As a side note, you may want to rethink your design and implement your Equals and GetHashCode using business key. You will not need Guid identity in this case. From Don’t Let Hibernate Steal Your Identity: