nhibernate

NHibernate - Name Primary key constraint?

Hi, We're starting to using NHibernate at my workplace, including generating the schema from the mappings. One thing our DBAs want is consistent names for the primary and foreign key relationships. I've been able to set the FK constraint name, but looking at the documentation for <id> it doesn't look like there's a way to name the pri...

Problem when getting an entity which has been modified in another session

Hello all, I have a strange problem in my rich client application. Here is some background: I use one session per view model. My view models communicate with each others with a Mediator. I have a management view model where I display a list of my entities. I can edit an entity, which results in the opening of a new view model, whic...

Problem faced while querying Using Nhibernate

I am having difficulties getting a subset of results From a huge set of results and then performing a join on this particular subset.. can anyone help regarding this?? More specifically, Say I have an student Table which contains 1000 rows of student and department table which has the list of departments. What I want to do is to get a...

exception occured while implementing full text search in NHibernate using named sql-queries

I am implementing a full text search using a view vw_SearchSite which has all the searchable fields and returning sites which have site IDs in common with the search results. the query: ..... SELECT DISTINCT {site.*} FROM v_Site {site} WHERE {site}.Id IN ( SELECT Id FROM vw_SearchSite WHERE CONTAINS(vw_SearchSite.*,:p...

NHibernate, how to read NamedQuery result metadata?

I have an sql-query define on my nhibernate mapping file, that call an stored procedure to select some records. <sql-query name="sp_MYSP"> exec MYDBSP :param1, :param2, :param3 </sql-query> On code, I call the named query in this way: IQuery myQuery= Session.GetNamedQuery("sp_MYSP"); myQuery.SetString("param1", p1); myQu...

nHibernate object mappings create key violations

Hi, Got a bit of an odd situation which I'm trying to map in Fluent nHibernate and failing. I have an Asset object which contains both an Image object and a File object. The Id of Image and File is identical, and the Image object contains a File object. This situation arises because an Image is always also a File (which is why the Id's ...

How to get results that begin with a number with NHibernate?

I have a table with a Name field containing data similar to the following: a1 a2 b1 c1 1a 1b 2a 9b I'm trying to select only the rows values that start with a number. I'm trying to do this with the following query, but it doesn't work: var numberGroups = _session .CreateCriteria<CompanyGroupInfo>() .Add(SqlExpression.Betwee...

Client and server validation

Hi, I'm developing application that use nHibernate for ORM, WCF services and silverlight as UI. My question is how to provide validation on server and also on client for domain entities. I thought using nHibernate validation framework but not sure if I can use it as client (silverlight) validation. I don't want to have two codes of valid...

Get property value of any entity in NHibernate in a generic way

Hi, I need to create a method like this: object GetPropertyValue(object entity, string databaseColumnName, int index); that will take any entity, a column name which is represented as a property in entity class and an optional index that is used if DB column is located inside collection property by some index. For example: Field e...

How to put a comment into HQL (Hibernate Query Language)?

Is it possible to put comments into Hibernate Query Language? If so, how? ...

Is there a HQL equivalent to datediff for NHibernate?

I haven't found a clear answer but I would like to grab any values from within the past 24 hours. I have an alternative solution in code but I would like to see if there is an equivalent to using t-sql datediff ...

Fluent NHibernate: How to map an IList<Dictionary<string, string>>

I would like to have a structure like this: Mapping class int ID {get;set;} IList<KeyValuePair<string,string>> Criteria {get;set;} Criteria class int ID {get;set;} int MappingID {get;set;} string FirstCriterion {get;set;} string SecondCriterion {get;set;} (int index {get;set;}) How can I get this keyvaluepair mapped? I tried with Ha...

Is it a good idea to test for id value while testing Fluent NHibernate mappings?

I'm working on tests for my Fluent NHibernate mappings, and my question is - is it a good idea to test for id value if Id column is represented by identity in Sql Server? Since it changes after each insert, how can I possibly do it? new PersistenceSpecification<Product>(session) .CheckProperty(p => p.Id, 1) ...

NHibernate - set fetch mode on grandchildren objects

I have the following Criteria query (using Lambda extensions): var workflowResult = repository.GetSession() .CreateCriteria<Core.Domain.Application>() .SetFetchMode<Core.Domain.Application>(app => app.ApplicationWorkflows, FetchMode.Join) .SetResultTransformer(new DistinctRootEntityRes...

Nesting Linq query with NHibernate

When I try to run this piece of logic, NHibernate comes back with an error stating it has no reference to "Site". IQueryable<Product> query = this.RetrieveAll(); query = query.Where(x => x.Status == Product.Statuses.Approved || x.SiteProduct.Where(y => y.Site.ID == siteID).Count() > 0); A little background. Product has a One to Ma...

Spring.net + NHibernate + .net MVC : Spring.Objects.Factory.UnsatisfiedDependencyException

With Sqllite provider,it works. But with sybase provider,it thows exception. Exception: Error thrown by a dependency of object 'SybaseAse-12' defined in 'assembly [Spring.Data, Version=1.3.0.20349, Culture=neutral, PublicKeyToken=65e474d141e25e07], resource [Spring.Data.Common.dbproviders.xml] line 1436' : Unsatisfied dependency ...

How to delete all database data with NHibernate?

Is it possible to delete all data in the database using NHibernate. I want to do that before starting each my unittests. Currently I drop my database and create it again but this is not acceptable solution for me. ========================================================== ok, here are the results. I am testing this on one database (Post...

Is it good to introduce nHibernate for a legacy database in an ongoing project?

I am working on a current ongoing project where, there are two instances of the database having different schemas for some of the tables and is being used for transfer from one to another. Database schema is not well defined like, No Primary key for some of the tables Primary key as a composite key Foreign keys in composite primary ke...

NHibernate : InvalidCastException

I am getting an InvalidCastException when connecting to sybase db. When i call BuildSessionFactory() i am gettign following error. Can somebody tell me what could be the reason... "Unable to cast object of type 'Sybase.Data.AseClient.AseConnection' to type 'System.Data.Common.DbConnection'." Thanks in advance. ...

Test DataAccess class build on WCF service

Hey, I put my NHibernate data access class in WCF service to can consume it by Silverlight project, but I have error and want to test my queries. It is possible to test this queries in service class using NUnit ? Earlier I test normally this class but how do it when it is in service class ?? It's my WCF service class: using System; us...