I am using the following generic code to save entities.
using (ITransaction tx = session.BeginTransaction())
{
try
{
entity.DateModified = DateTime.Now;
session.SaveOrUpdate(entity);
session.Flush();
tx.Commit();
return entity;
}
catch (Exception)
{
tx.Rollback();
thro...
I'm creating a blog library using nHibernate and I have a BlogEntry class that has a CreatedBy property of type User (User is an abstract class). The two concrete implementations of the User class are RegisteredUser and UnknownUser. I'd like nHibernate to instantiate UnknownUser class if the value in the CreatedBy field is null. If it i...
How would you map the following in Fluent NHibernate?
See "18.3. Customer/Order/Product"
http://www.hibernate.org/hib_docs/nhibernate/html/example-mappings.html
...
So I'm converting my mapping files on an as needed basis (when making
changes, convert to mapping). Any when configuring NHibernate like so:
Assembly asm = Assembly.Load("RPMWare.Core.DataAccess");
//NHibernate configuration: see hibernate.cfg.xml
var cfg = new Configuration();
cfg.AddMappingsFromAssembly(asm);
cfg.Configure();
And r...
when I am setting up my fluent mappings, what is the default for collections? Do I need to explicitly set them as lazy-load, or is that the default?
...
Hello,
I am using the SQLite database and have the following persistent class (simplified):
public class Project
{
public virtual int Id { get; set; }
public virtual DateTime StartDate { get; set; }
}
which is mapped to this table in the database:
CREATE TABLE projects (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
...
I'm trying to map a joined-subclass scenario using Fluent NHibernate.
I have a class Entity defined in the namespace Core, and a class
SubClass : Entity in the namespace SomeModule
Now I obviously don't want class Entity to know about its derived
types, the SomeModules namespace references Core - not the other way
around.
All the examp...
I'm trying to get distinct results using the Criteria API in NHibernate. I know this is possible using HQL, but I would prefer to do this using the Criteria API, because the rest of my app is written using only this method. I found this forum post, but haven't been able to get it to work. Is there a way with the criteria API to get disti...
I'm building a new app that is using NHibernate to generate the database schema but i can see a possible problem in the future.
Obviously you use all the data from your database is cleared when you update the schema but what stratagies do people use to restore any data to the new database. I am aware that massive changes to the schema w...
I'm not sure how to ask the question, for I don't know what I don't know, and therefore I don't know the proper terminology for what I'm trying to get the answer to. I will explain my scenario, in hopes that it will help:
I've got three tables, a Book table, a Tag table and a BookTag lookup table.
Each book has an ID, a Title (for sta...
Hi
I have a legacy db that I am mapping with Nhibernate.
And in several locations a list och strigs or domain objects are mapped as a delimited string in the database. Either 'string|string|string' in the value type cases and like 'domainID|domainID|domainID' in the references type cases.
I know I can create a dummy property on the cla...
Can anyone point me out, how can I parse/evaluate HQL and get map where key is table alias and value - full qualified class name.
E.g. for HQL
SELECT a.id from Foo a INNER JOIN a.test b
I wish to have pairs:
a, package1.Foo
b. package2.TestClassName
It's relatively easy to do for result set
HQLQueryPlan hqlPlan = ((SessionFac...
Hi,
I'm trying to do a simple "Select Count(*) from PRODUCTS where date > xxx" with Castle on NHibernate.
If I was directly using NHibernate, I could reuse this question answers but unfortunately I see no easy way to access the Current NHibernate session from Castle Records.
I obviously don't want to retrieve all my objects and do a C...
I have an Events table whose goal is to store actions done by web site users. An action basically alters or create a new row in a table X. This will allow me to store an history of all actions done by a user. As such, Events contains:
a primary key column
a text to describe the event (ex: "posted a comment")
a discrimator column if nee...
I need to write a row to the database regardless of whether it already exists or not. Before using NHibernate this was done with a stored procedure. The procedure would attempt an update and if no rows were modified it would fallback to an insert. This worked well because the application doesn't care if the record exists.
With NHibernat...
Here are the domain model classes:
public abstract class BaseClass
{
...
}
public class ChildClass : BaseClass
{
...
}
Note that the parent class is abstract and this is what gives me some difficulties when comes the time to map with fluent nhibernate. My discriminator is a byte (tinyint in the DB). Because it is not a string and I c...
Is there any supported way of mapping datetimeoffset the new datatype in SQL 2008 to the System.DateTimeOffset using nhibernate?
...
Are there any books on the subject that anyone recommends? Where do I learn the key concepts and patterns for ORM in general as it relates to NHibernate specifically?
...
Hello there.
Does hibernate HQL queries support using select min, max, count and other sql functions?
like
select min(p.age)
from person p
Thanks
...
Are there any optimizations to consider when connecting to Oracle with NHibernate? My calls to Oracle are taking an extremely long time. If I run the NHibernate query (copied from my output window in Visual Studio) directly against Oracle, it comes right back in under a second. Here is my config file for NHibernate. I can post the mappin...