I'm starting a new project and plan on using nhibernate. I'm struggling with whether or not I should keep my domain model clean of persistence information by leaving out foreign keys. I keep feeling like some of my "model" isn't really necessary and that performance is going to be an issue. For example:
In my db I have the following tab...
I have the following database schema:
And this is my mapping file:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="CodeSmithSampel.Generated.BusinessObjects" assembly="CodeSmithSampel">
<class name="CodeSmithSampel.Generated.BusinessObjects.Store, CodeSmithSampel" table="st...
How to use Inverse Attribute? If I am not mistaken, for one to many relationship the inverse attribute must be set to true. For many-to-many one of the entity class inverse attribute must be set to true and another set to false.
Anyone can shed some lights on this?
...
I have a simple entity that has an Id (the primary key) and a string name. I'm looking for a way to tell nHibernate not to allow duplicate names in the table.
I'd like to have an Add method that can take a new entity (with Id = 0), and if necessary add the new entity & update Id. This works now. If the name already exists in the ta...
Hi, just started out with NHIbernate and have one question, probably a bit of a stupi one! ;-)
I have 2 tables, Email and Attachment, an email can have zero or more attachments. so I created a hbm file like this:
<set name="Attachments" table="Attachments">
<key column="E...
I need to create a query in NHibernate that would search for a product of two columns, like this:
WHERE a*b = param1
leaving efficiency aside (assume I have little rows or actual query will have extra conditions that will exploit some indexes) how do I do it in NHibernate? Preferably the solution should work with DetachedCriteria. I kn...
I want to create generic drop down list in ASP.net 2.0 using C#, basic concept is which ever Nhibernate object type with which I initialize this list it should populate dropdown with all values from that objects underlying table. Any suggestions how can I achieve this.
...
This has got to be a lamer question:
In my test project I am attempting to configure log4net. The following method call gives the error.
BasicConfigurator.Configure();
"type name expected but method found"
What am I overlooking?
Thanks,
Nick
...
With HQL I can use dynamic instantiation like this:
select new ItemRow(item.Id, item.Description, bid.Amount)
from Item item join item.Bids bid
where bid.Amount > 100
Now I need to create my queries dynamically with the Criteria API. How can I obtain the same results that I would have obtained with HQL, but using the Criteria API?
Th...
I have the following property on a class persisted with NHibernate:
public virtual string Code
{
get { return Id.ToString("SP000"); }
}
However I've come to do this, which of course doesn't work:
Session.Linq<MyType>().Where(x => x.Code.Contains(searchTerm));
So, is it possible to store Code in the database and have NHibernate ...
I am trying to persist an object with a collection of child objects. I can't persist the children first as there is a FK relationship. I could save the parent first and then add the children on to it, but this would introduce more work. Basically I'm just trying to save a fully populated object in one step and not break it into parts. Is...
Is there any way to get NHibernate to let me store multiple ChildObjects in the ChildObjectTable but refer them back to different ParentObjects? Or do I have to create a separate ChildObject class/table for each ParentObject type?
I've boiled this down to the following, I'm trying to map these objects:
public class ParentObjectA
{
...
I've the following many to many relation: File 1 --- * File_Insurer * --- 1 Insurer. I'm trying to query this relation using the Criteria API (Active Record) to get Files that meet ALL specified Insurers (Get all Files where Insurer.Id == 2 AND Insurer.Id == 3).
Mapping files (parts):
File
[HasAndBelongsToMany(typeof(Insurer),
Table =...
Hello!
I have the following XML (.hbm):
<property name="Geometry" column="the_geom">
<type name="NHibernate.Spatial.Type.GeometryType,NHibernate.Spatial">
<param name="subtype">MULTIPOLYGON</param>
<param name="srid">-1</param>
</type>
</property>
It´s using Nhibernate Spatial type...
How can I map that property...
Hi, I can't get sum() to return decimal and it always returns int64 truncating the decimals. I have Googled for a whole day but still can't find a real work around. I have a DB table called ProductPurchase with
QtyPurchased(int)
and
UnitPurchasePrice(money) columns,
these are mapped to a C# POCO object using NHibernate,
where
Qt...
I'm trying to get nHibernate to join the name of the structure that is stored in separate table into the structure POCO object.
The database looks something like this:
+-----------+ +------------+ +-----------+
| Structure | | Texts | | Languages |
+===========+ +============+ +===========+
| Id | | Id | | I...
My application is using Rhino.Commons - NHRepository and UnitOfWork. I like the With.Transaction() syntax for transactions and have been using it for some time.
But I ran into a problem - how do I mock a UnitOfWork for testing? Especially this is causing trouble for me:
With.Transaction(() => Repositories.TwinfieldSpooler.Update(spool...
NHibernate provides us with ORM capabilities. Part of NHibernate generates queries based on mappings and HQL (or ICriteria). I'm wondering if it is possible to use NHibernate for generating queries against databases without using its ORM capabilities.
I'm trying to provide customers with custom access to their database. Since the schema...
How do I query for data added as IndexEmbedded?
I have an entity class
[Indexed]
public class Something
{
[Field(Index.Tokenized, Store = Store.Yes)]
public virtual string Description { get; set; }
[IndexedEmbedded]
public virtual Category Category { get; set; }
[IndexedEmbedded]
public virtual Location L...
I'm using the NHibernate HBM2DDL SchemaExport tool to generate my database from my entity objects, and I want to use SQL Server Timestamp columns for optimisitic concurrency.
I've added properties to my entity object that look like this:
public virtual byte[] Timestamp { get; set; }
NHibernate will generate the Timestamp column, but t...