I have a class called Continent and Country.
Continent class has Country collection:
private ISet<Country> _countries;
public virtual ISet<Country> Countries
{
get { return _countries; }
set { _countries = value; }
}
I want to write an HQL query that will get all the continents that have countries at l...
I have an NHibernate entity which contains a many-to-many list of related items. When a certain property of the entity changes, a database trigger is called that removes all associations between the entity and any entities that it is joined to. However, NHibernate throws a StaleStateException with a message along the lines of:
Batch u...
I have an entity Person:
public class Person
{
public virtual int Id {get; set; }
public virtual string FirstName { get; set; }
public virtual string MiddleName { get; set; }
public virtual string LastName { get; set; }
}
with the mappings:
public class PersonMap
{
public PersonMap()
{
Table(TABLE_NAME);
...
I'm trying to create a not in clause with the NHibernate Criteria API using NHLambdaExtensions. Reading the documentation I was able to implement the in clause by doing
.Add(SqlExpression.In<Zone>(z => zoneAlias.ZoneId, new int[] { 1008, 1010 }))
However, when I wrap it around SqlExpression.Not I get the error
Error 5 The best ov...
How can I map properties of a type with no NHibernate mapping?
How should I manage the dependencies on old data access logic during the transition?
The application uses ADO.NET to invoke sprocs for nearly every database operation. Some of these sprocs also contain a fair amount of domain logic. The data access logic for each domain e...
I have a query which has an Order By clause. The generated SQL from NHibernate looks like
ORDER BY coalesce(x.Company as x__.Company, y.Company) asc
This fails as 'as' is not allowed in Order by clause in MS SQL Server. Is there any way I can prevent aliasing?
The criteria query that I have written looks like:
var orderBy = Proj...
We are attepting to profile our NHibernate application using NHProf. We have a series of unit tests which exercise various calls. However, if we run the unit test multiple times, we get differing results in NHProf:
Session 1 [1]
Session 2 [32]
Session 3 [32]
Session 4 [2]
Session 5 [2]
I've tried calling session.Clear() at the end of...
I have an ASP.NET MVC application that also employs the typical NHibernate / Castle stack. On startup, the application's memory footprint sits around 190Mb and I wish to be able to run multiple isolated AppPools, each of which will serve a different domain. This is before really hitting anything serious in the database or putting anythin...
public Parent GetByName(string Name)
{
return _session.CreateCriteria<Parent>()
.Add(Restrictions.Eq("Name", Name))
.SetFetchMode("Children", FetchMode.Eager)
.SetResultTransformer(new DistinctRootEntityResultTransformer())
.UniqueResult<Parent>();
}
public ParentDetailVM GetMeAParent(string Name)
{
...
I get this error:
a different object with the same
identifier value was already
associated with the session: 63, of
entity: Core.Domain.Model.Employee
Within my ASP.NET MVC controller actions I do this:
public ActionResult Index(int? page)
{
int totalCount;
Employee[] empData = _employeeRepository.GetPagedEmployees(p...
I'm trying to delete a database record using ASP.NET MVC, Fluent, and NHibernate. See the code below for examples of how I'm trying to accomplish this. I am able to Get, Update, and Insert records but Delete is not working. When the Delete() method gets called in the controller (top one) it throws an Exception (System.Data.SqlClient.SqlE...
I've got
class Parent
{
IList<Child> Children;
}
class Child
{
}
When deleting a Child I need to remove all references to it from any Parents that reference it.
How can I do this in NHibernate?
There is no Parent FK on Child, the relationship is stored in a 3rd "link" table
Thanks
...
Hello I want to generate a sql query with ICriteria interface like that
select * from tableName where (dataColumn like '%2010-06-09%')
I researched in google and I found CONVERT() function to do this:
SELECT * FROM DATE_SAMPLE
WHERE CONVERT(CHAR(10),SAMPLE_DATE,120) = '2003-04-09'
How can I do this in NHibernate wtih ICriteria?
...
I have a simple NHibernate domain model with Users and Roles. There's a many to many association between User and Roles. Simplified entities:
public class User : Entity<Guid>
{
private IList<Role> _roles;
public User()
{
_roles = new List<Role>();
}
public virtual UserName { get; set; }
public virtua...
I have a visual studio solution with an ASP.NET 3.5 web application (WCF host) and a test project. I wanted to use the Oracle Instant Client (v11, via NHibernate) to create Oracle connections without having the Oracle client tools installed on every "involved" machine (dev, CI server, test server, production server).
The weird thing is ...
So let me start by saying that the weird thing about this error is that the application is running, and the error bubbles to the event log, but it's intermittent. Sometimes it's 2 hours between it happening, sometimes a few minutes, sometimes half an hour. Does not appear to be tied directly to requests (and requests don't seem to be f...
I want to find out the amount of people that have read x number of books.
The setup is that I have a "Person" and a "ReadBooks" class.
What I tried to do is:
var innerProjection = Projections.ProjectionList()
.Add(Projections.GroupProperty("Person"), "Persons")
.Add(Projections.Count("Person"), ...
I have a tiny problem with NHibernate and I can't figure out why. Every time I debug or profile the application and I accidently violate a unique constraint NHibernate just won't run any more multiqueries (I'll leave the exception stack trace till last). The flow is this. Everything works fine and then:
Violation of UNIQUE KEY constr...
I have been searching the web for several hours to try to get an answer on this, but to no avail.
What I am trying to do is AND 'N' amount of Disjunctions to refine searches based on white space delimited query.
I have a 'Unity' which can be any combination of either a single person or organisation or multiple people/organisation, or a...
[NUnit.Framework.Test]
public void Test2()
{
NHibernate.ISession session = Z.Core.NHibernateCore.NHibernateHelper.GetCurrentSession();
var crit = session.CreateCriteria("_School");
crit.CreateCriteria("ListStudent", "_ListStudent", NHibernate.SqlCommand.JoinType.LeftOuterJoin);
crit.Add(NHibernate.Criterion.Expression.Eq("__ListStudent.N...