nhibernate

How would I design a repository to handle multiple data access strategies?

佐手、 提交于 2020-01-12 06:23:28
问题 What would a skeleton design look like for a repository able to support multiple database layers using ASP.NET MVC and C#? I want to see what a design would look like if I support both LINQ to SQL and NHibernate. How would I create my database object, and call a method on it in my BLL layer? 回答1: The repository pattern is probably the best solution for this. You would define an interface for each repository, then create concrete repositories for Linq2Sql and NHibernate implementations, e.g.

Struggling to Comprehend nHibernate SchemaUpdate, even with Blog Posts

Deadly 提交于 2020-01-12 05:30:29
问题 I've seen the various blog posts concerning nHibernate's SchemaUpdate , and even Ayende's very good example, and downloaded the samples, but for some reason I cannot get the same same thing to work for me. I will note that I am using Fluent NHibernate , but from what I can tell that should not make too huge a difference. Update I have reached the point where the SchemaUpdate runs, but it is just a full schema creation, no 'altering'. In otherwords, it's the same as if I just built the

Install NHibernate 3.2 with NuGet

☆樱花仙子☆ 提交于 2020-01-11 19:56:22
问题 I'm new to NHibernate and have been trying to get up and running with it, Fluent NHibernate and NHProf using NuGet. After reading this article (http://gurustop.net/blog/2011/03/13/nhibernate-3-1-0-on-nuget-important-details) it seems that v3.1 shouldn't be directly installed, however, there appears no such warning for v3.2. After successfully installing NHibernate 3.2 and NHProf using NuGet, I'm unable to install Fluent NHibernate as it says it's "Already referencing a newer version of

NHibernate Session.Flush() Sending Update Queries When No Update Has Occurred

ぐ巨炮叔叔 提交于 2020-01-11 17:08:10
问题 I have an NHibernate session. In this session, I am performing exactly 1 operation, which is to run this code to get a list: public IList<Customer> GetCustomerByFirstName(string customerFirstName) { return _session.CreateCriteria(typeof(Customer)) .Add(new NHibernate.Expression.EqExpression("FirstName", customerFirstName)) .List<Customer>(); } I am calling Session.Flush() at the end of the HttpRequest , and I get a HibernateAdoException . NHibernate is passing an update statement to the db,

NHibernate thread safety with session

流过昼夜 提交于 2020-01-11 15:30:28
问题 I've been using NHibernate for a while now and have found from time to time that if I try to request two pages simultaniously (or as close as I can) it will occasionally error. So I assumed that it was because my Session management was not thread safe. I thought it was my class so I tried to use a different method from this blog post http://pwigle.wordpress.com/2008/11/21/nhibernate-session-handling-in-aspnet-the-easy-way/ however I still get the same issues. The actual error I am getting is:

NHibernate : recover session after connection lost

谁说胖子不能爱 提交于 2020-01-11 12:12:15
问题 I'm using NHibernate with SQL Server 2005 in a WPF client application. If I manually stop the SQL Server service and then restart it the session doesn't automatically reconnect. So far I'm doing this witch seems to work : try { using (ITransaction transaction = this.Session.BeginTransaction()) { // some select here } }catch(Exception ex) { if(this.Session.Connection.State == ConnectionState.Closed) { try { this.Session.Connection.Open(); } catch (Exception) { } } } Is there a better way ? 回答1

How can the NamedSQLQueryDefinition class be used dynamically as a sql-query equivalent?

倖福魔咒の 提交于 2020-01-11 11:59:07
问题 I need to dynamically add named queries to the NHibernate configuration object. The search engines return few hits referencing NamedSQLQueryDefinition or NamedQueryDefinition. Below is what I'm attempting to do. I don't know what to provide to the NamedSQLQueryDefinition constructor to successfully create a query. Can anyone provide a sample of how to create a new NamedSQLQueryDefinition the right way? Thanks!! Session initializer: private static ISessionFactory CreateSessionFactory() { var

linq (to nHibernate): 'like in' operator

↘锁芯ラ 提交于 2020-01-11 10:22:08
问题 Hi Given a list of strings I want to retrieve all items whose names contain one of the given strings. for example- given {"foo", "kuku"} I want to retrieve the employees "Corfoo", "kuku maluku" and "kukufoo". I've tried the following, but got a null-reference exception(?) query.Where(u => values.Any(v=> u.FullName.Contains(v)) ); The following produced a 'Lambda expression not in scope' exception. query.Where(u => (values.Count(v => u.FullName.Contains(v)) > 0) ); any idea how this can be

Lazy Loading in NHibernate

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 09:51:49
问题 If a Customer has many Orders attached to them. How would you lazy load the Orders List using NHibernate. Is it something that needs to be set up mapping file? any help or an example would be great. 回答1: Heres a good article: http://blogs.chayachronicles.com/sonofnun/archive/2007/03/30/230.aspx From the above article: The most common is to simply mark the class with the 'lazy="true"' attribute or place 'default-lazy="true"' in the mapping declaration: <hibernate-mapping xmlns="urn:nhibernate

Lazy Loading in NHibernate

試著忘記壹切 提交于 2020-01-11 09:51:41
问题 If a Customer has many Orders attached to them. How would you lazy load the Orders List using NHibernate. Is it something that needs to be set up mapping file? any help or an example would be great. 回答1: Heres a good article: http://blogs.chayachronicles.com/sonofnun/archive/2007/03/30/230.aspx From the above article: The most common is to simply mark the class with the 'lazy="true"' attribute or place 'default-lazy="true"' in the mapping declaration: <hibernate-mapping xmlns="urn:nhibernate