Questions tagged [nhibernate]

NHibernate is an open source object-relational mapper (ORM) for the .NET framework.

NHibernate is an open source object-relational mapper (ORM) for the .NET framework.

It started as a .NET port of the popular Java ORM Hibernate.

Installation

Installing NHibernate can most easily be done using its NuGet package:

Install-Package NHibernate 

Resources

17428 questions
256
votes
7 answers

What are the First and Second Level caches in (N)Hibernate?

Can anyone explain in simple words what First and Second Level caching in Hibernate/NHibernate are?
suhair
  • 10,597
  • 10
  • 50
  • 63
188
votes
4 answers

NHibernate ISession Flush: Where and when to use it, and why?

One of the things that get me thoroughly confused is the use of session.Flush,in conjunction with session.Commit, and session.Close. Sometimes session.Close works, e.g., it commits all the changes that I need. I know I need to use commit when I have…
Jon Limjap
  • 89,838
  • 14
  • 96
  • 150
135
votes
17 answers

NHibernate.MappingException: No persister for: XYZ

Now, before you say it: I did Google and my hbm.xml file is an Embedded Resource. Here is the code I am calling: ISession session = GetCurrentSession(); var returnObject = session.Get(Id); Here is my mapping file for the class:
Sara Chipps
  • 9,152
  • 11
  • 54
  • 102
117
votes
9 answers

NHibernate vs LINQ to SQL

As someone who hasn't used either technology on real-world projects I wonder if anyone knows how these two complement each other and how much their functionalities overlap?
Manu
  • 27,156
  • 27
  • 70
  • 82
112
votes
3 answers

Moq: Invalid setup on a non-overridable member: x => x.GetByTitle("asdf")

Not sure how I can fix this, trying to do a unit test on the method "GetByTitle" Here are my definitions: public class ArticleDAO : GenericNHibernateDAO(IArticle, int>, IArticleDAO { public IArticle GetByTitle(string title) { IQuery…
mrblah
  • 88,033
  • 134
  • 292
  • 404
111
votes
4 answers

List vs Set vs Bag in NHibernate

What's the difference between a list, set and bag in the NHibernate mapping file? How does each relate to .NET collections?
mrblah
  • 88,033
  • 134
  • 292
  • 404
108
votes
8 answers

How can you do paging with NHibernate?

For example, I want to populate a gridview control in an ASP.NET web page with only the data necessary for the # of rows displayed. How can NHibernate support this?
Ray
  • 169,974
  • 95
  • 213
  • 200
104
votes
4 answers

Best way to convert IList or IEnumerable to Array

I have a HQL query that can generate either an IList of results, or an IEnumerable of results. However, I want it to return an array of the Entity that I'm selecting, what would be the best way of accomplishing that? I can either enumerate through…
jishi
  • 22,747
  • 6
  • 45
  • 73
102
votes
2 answers

How does TransactionScope roll back transactions?

I'm writing an integration test where I will be inserting a number of objects into a database and then checking to make sure whether my method retrieves those objects. My connection to the database is through NHibernate...and my usual method of…
mezoid
  • 26,370
  • 35
  • 104
  • 147
94
votes
2 answers

Criteria SpatialRestrictions.IsWithinDistance NHibernate.Spatial

Has anyone implemented this, or know if it would be difficult to implement this/have any pointers? public static SpatialRelationCriterion IsWithinDistance(string propertyName, object anotherGeometry, double distance) { // TODO: Implement …
Ian
  • 1,589
  • 11
  • 20
89
votes
3 answers

Inverse Attribute in NHibernate

How do I use the Inverse Attribute? If I am not mistaken, for one to many relationships the inverse attribute must be set to true. For many-to-many relationships, one of the entity class inverse attributes must be set to true and another set to…
Graviton
  • 76,900
  • 138
  • 399
  • 575
88
votes
2 answers

What is the difference between JoinQueryOver and JoinAlias?

I need to know what is the difference between JoinQueryOver and JoinAlias, and when to use each?
Luka
  • 3,402
  • 2
  • 30
  • 53
88
votes
7 answers

How do you map an enum as an int value with fluent NHibernate?

Question says it all really, the default is for it to map as a string but I need it to map as an int. I'm currently using PersistenceModel for setting my conventions if that makes any difference. Thanks in advance. Update Found that getting onto the…
Garry Shutler
  • 31,001
  • 11
  • 77
  • 118
87
votes
6 answers

What's the difference between session.Merge and session.SaveOrUpdate?

I notice sometimes with my parent/child objects or many-to-many relationships, I need to call either SaveOrUpdate or Merge. Usually, when I need to call SaveOrUpdate, the exception I get on calling Merge has to do with transient objects not being…
EvilSyn
  • 2,262
  • 7
  • 23
  • 22
85
votes
2 answers

Unable to cast object of type NHibernate.Collection.Generic.PersistentGenericBag to List

I have a class called ReportRequest as: public class ReportRequest { Int32 templateId; List entityIds; public virtual Int32? Id { get; set; } public virtual Int32 TemplateId { get { return…
inutan
  • 9,740
  • 25
  • 74
  • 119
1
2 3
99 100