Schema:
Users
ID
Name
Password
Address
ID
Street
UserID
Both tables have an ID field (guid).
Code:
User u = new User();
u.Address.Street = "test";
session.Save(u);
How can I create a mapping file to use the UserID from the address table to point
to the ID from the Users table and reflect my sample code above?
...
I am writing some unit test and I have a unit testing base class which opens the transaction and closes the transaction. The purpose of the transaction is to rollback the changes so the database is empty once the unit tests are finished running. The transaction is dependent on the ISession object.
Now, the problem is that my CustomerRe...
Hi guys,
Does set,bag while cascading is used for Ilist or Iset only.
What if the entity is not a list, just a non collection relationship.
In that case what should we use while cascading.
...
Hi,
I have an array of bytes in my C# class, and need to persist it into a SQL Server 2005 database using NHibernate. What SQL data type should I use for the column, and how do I got about using NHiberante to do the persistance for me? If the answer is a custom NHibernate type, is there any sample code knicking around to do this?
Would...
Hi,
I am a newbie with NHibernate, so please bear with me.
Let's imagine, i have a property for CreatedDate, and i wanted it to be filled with the sql server datetime value.
The possible solution that i found out is, to mark this property as "generated=always" with "insert=false" and "update=false", and then set the default value for...
I've just started using NHibernate, and I have some issues that I'm unsure how to solve correctly.
I started out creating a generic repository containing CUD and a couple of search methods. Each of these methods opens a separate session (and transaction if necessary) during the DB operation(s). The problem when doing this (as far as I ...
Hi,
How can I get fluent nhibernate to create a varbinary field in a sql server 2005 table that uses a field size of varbinary(max)? At the moment I always get a default of varbinary(8000), which isn't big enough as i'm going to be storing image files.
I've tried using CAstle.ActiveRecord but havent had any success yet.
[ActiveRecord...
I'm trying to map the output of a stored procedure to an object in my project using nHibernate.
The object is delcared like this:
public class NewContentSearchResult
{
public string Name { get; set; }
public string ContentType { get; set; }
public int Count { get; set; }
public int CMIId { get; set; }
public int Fea...
I need to Inject some global service (daoFactory) into EventListenet subscribed on PostUpdate event. I`ve read that it is possible to do this way:
public class YourPostInsertListener : IPostInsertEventListener
{
private readonly IPersistentAuditor auditor;
public YourPostInsertListener(IPersistentAuditor auditor)
{
this.auditor = a...
I was reading a blog-post of Ben Scheirman
http://flux88.com/blog/blame-nhibernate-why-not/ about some NHibernate tweaks he made in order to increase the performance.
In the end of article there is
Lesson #7: Always make sure you’ve set hibernate.default_schema
What does he mean by hibernate.default_schema?
...
I have an entity A who has entity B.
Class Entity A
{
public EntityB;
}
Class Entity B
{
public Entity A;
}
Entity B has one to one relationship with A.
I am trying to use cascade save,delete when entity A is saved so that I don't have to manually save entity B. It shpould be done automatically.
my mapping for entity B looks...
Salesforce’s secret sauce: It queries its databases with “The Multi-Tenant Optimizer" So exactly what could this practice be comprised of?
...
I'm modeling a very basic ASP.NET MVC app using NHibernate and I seem to be stuck on my design. Here's a sketch of my model:
As you can see this is VERY basic but I have some concerns about it. The User root entity and the Organization root entity are accessing the same Organization_Users entity child via two one-to-many relationship...
New to NHibernate and learning it as we are modifying an existing solution to use this ORM.
Ideally, the storage structure and object classes need to stay the same, so Ive come across one or two mapping problems.
One class 'Money' has a value and currency. The value is a double and the currency is a foreign key to a list table of curren...
I have a pretty standard Repository pattern going, where repositories are injected into my MVC controller at construction. Repositories are initialized once per AppDomain and are shared by other controllers. Repositories access the database using NHibernate ISessions and ICriteria, but access is exposed using ListXYZ methods instead of a...
Hi!
I would like to make a query which needs to compare an property's property with some value. For example:
... WHERE Identity.Location.Room = "room #1"
How can I achieve this with criteria api?
Best RegardsOliver Hanappi
...
In my class Case I have an IDictionary with Entity (a class) as key and Roles (an enum) as value. When trying to save a new instance (non-persisted) of Case, where the IDictionary is filled with new instances of Entity I get the following error:
NHibernate.TransientObjectException: object references an unsaved transient instance - sa...
NHibernate Version: 2.1
I'm using what seems to be a pretty standard HttpModule approach to implementing per-request sessions in an ASP.NET+NHibernate application. I'm trying to leverage WebSessionContext, but it doesn't seem to be working correctly. Specifically, everything works brilliantly for the first request on the application, bu...
Hi!
I have a following HQL query:
SELECT s.id
FROM
stack s
WHERE
s.category is not empty
Basically, s.category is a one-to-many join to another table (Category).
I need to check whether the collection is empty or no. I can do it in c# code (just run through all of the Stacks and check if Stack....
How would you test the following code?
public IList<T> Find(DetachedCriteria criteria)
{
return criteria.GetExecutableCriteria(session).List<T>();
}
I would like to mock NH implementation (like setting mocks for ISession, ISessionFactory etc.) but I am having trouble with this one.
...