nhibernate

entity property that is nullable

I want my nhibernate entity property to be nullable. the column is a nvarchar(MAX) in sql server, and it can be NULL. How do I map this using the xml mapping? ...

Linq to Nhibernate question

Consider this 3 classes public class ClassA { public IList<ClassB> BList {get; private set;} } public class ClassB { public ClassC C {get; private set;} } public ClassC { //doesn't matter } I want to get all ClassA instances from the repository, that has at least one BList element containing a specific C instance, that i...

SchemaExport vs HiLo algorithm

I'm using schemaExport to create an in-memory database for my automatic tests. I have several (5) classes mapping their HiLo identity to the same database table, using one column per class. This gives me a table, hibernate_unique_key, w. 5 columns. When generating the database using scemaexport, however, the table only gets a single col...

Inheritance: Criterion on entity type and sub class properties

I have a inheritance hierarchy which I have mapped in NHibernate using Table-per-class. My mappping file looks like the one below (lots of properties omitted). To query this hierarchy, I am building a dynamic DetachedCriteria for Message based on filter input from the user. Messages (of any type in the hierarchy) should be returned to t...

Using an sql-function when reading and writing with NHibernate

Hi, I have the following problem. I have a special column in my tables (a blob). In order to read and write to that column, I need to call an SQL function on its value - to convert to a string when I read, and to convert from a string to this blob when I write. The read part is easy - I can use a formula to run the sql function agains...

How do I map an optional one-to-one relationship with Fluent NHibernate?

I've got two entities, one called Site and the other called Assignment. A Site may or may not have an associated Assignment. An Assignment is only ever associated with one Site. In terms of C#, Site has a property of type Assignment which could hold a null reference. I have got two tables by the same names in the database. The Assignmen...

How do you build extensible data model

Hi, I'm thinking of building a ecommerce application with an extensible data model using NHibernate and Fluent NHibernate. By having an extensible data model, I have the ability to define a Product entity, and allow a user in the application to extend it with new fields/properties with different data types including custom data types. ...

C# with Nhibernate

i want to write to database table which has composite id using NHibernate.This is the code that i used.but it didnt work. <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="NHibernatePets.junctionstatistic, NHibernatePets" lazy="true"> <composite-id> <key-property name="junction...

how to set session for a console application?

I have a c# library for my web application where I am using nhibernate. The web application has the hibernate.cfg.xml file where I set: current_session_context_class = web I am using a nhibernateHelper class and a httpmodule to open and close the session on a per request basis. I now need to use this library in a console application, ...

multiple results in a single call

When paging data, I want to not only return 10 results, but I also want to get the total number of items in all the pages. How can I get the total count AND the results for the page in a single call? My paged method is: public IList GetByCategoryId(int categoryId, int firstResult, int maxResults) { IList<Article> arti...

Fluent NHibernate table per subclass inheritance mapping

I'm new to NHibernate and Fluent NHibernate. I'm wondering how to properly use Fluent NHibernate with the "table per subclass" mapping strategy. This is an example of what I'm after. More specifically though, I need a way to break the subclass mappings into separate files. Also, when adding records, I need NHibernate to first insert in...

how to get the total count of rows

from my previous question: http://stackoverflow.com/questions/1947026/multiple-results-in-a-single-call how would I get the count of all articles in a given category? I prefer criteria query if possible (would love it if you could show me how to do it in both criteria and hql) ...

rewriting a SQL/vb6 app - should I use nHibernate or Linq

Hi experts, I have a legacy VB6 app which I am rewriting in .Net. I have not used an ORM package before (being the old fashioned type who likes to know what SQL is being used), but I have seen good reports of NNibernate and I am tempted to use it for this project. I just want to check I won't be shooting myself in the foot. Because my ...

how would I convert this join using Criteria query?

my create query (HQL) looks like: Session.CreateQuery( "select a from Article as a join a.Categories c where c.ID = :ID") .SetInt32("ID", categoryId) ...

Modelling a shared entity puzzle

Have the following entities in my domain: Project Task User Context A user can have multiple projects, tasks and contexts. A project can have tasks and contexts and a task can have contexts. I am a little unsure as how best to model Contexts as it will belong to multiple entities i.e. a user can add a list of contexts, these context...

Can someone give me a mapping example of two NHibernate classes that have composite keys and one-to-many?

Can someone please give me an example of what the mappings would look like for two classes that both have composite keys and a one-to-many relationship? I have looked everywhere and tried 100 different things with no luck. E.g., HeaderTable -HCONO Decimal -HDVNO Decimal -HDTTK Decimal -HDES2 String -HDESC String -HDESC3 String HCO...

Find Underlying Column Size Via NHibernate Metadata

Hi, Is there a way to use SessionFactory.GetClassMetadata(), or any other method you're aware of, to dynamically get the maximum size of a varchar column that underlies an NHibernate class' string property? To clarify, I'm not looking to read a length attribute that's specified in the NHibernate mapping file. I want to deduce the actu...

Want to manage SQL Server dynamically in c#

I want to manage SQL Server dynamically, that is through code I wan to scan SQL Server for available databases than I want to create new database, access older database, alter it, and insert data into database depending upon table schema what is better approach what should I use? i heard name of nhibernate, SQL Server Management Object ...

How do I set the Fetchmode on all assocations of a nHibernate ICriteria in one go?

I have an object that has many assocations to other objects. All of these are fetched lazily by nHibernate, which is good in almost all cases. In a particular scenario, in this case an export of a lot of records, I want to set the Fetchmode to eager on all associations. Is there a way to do this, without having to manually specify each...

nhibernate Dynamic Insert fails with some null Component properties

I have a database that accepts no null values and has a default for every field. Using fluent nHibernate, I am getting an error on an Insert if I have a component that has some, but not all properties filled out. I am just wondering how to get the DynamicInsert flag down to the component level. Perhaps it is late, but I'll just drop t...