nhibernate

Expression Trees

I have a method which have this signture public static IList<T> GetBy<T>(System.Linq.Expressions.Expression<Func<T, bool>> expression) i use to pass lambda expressions and make search restriction in nhibernate by reteriving data from expressiontree so when class user pass something like : c => c.fullName == "John" && c.lastName == "...

Fetching previous and next row as well as current row using NHibernate

I have the following code in my repository. I use it for a product details page. public Product GetBySlug(string slug) { return session.CreateCriteria(typeof(Product)) .SetFetchMode("CrossSell", FetchMode.Eager) .Add(Expression.Eq("Slug", slug)) .UniqueResult<Product>(); } This query currently gets one prod...

NHibernate Linq - why does it use join when querying foreign key field?

Hi all I have a object model a bit like this: public class Foo { public int Id {get;set;} public string FooName {get;set;} } public class Bar { public int Id {get;set;} public Foo Foo {get;set;} } These correspond to tables in the database in the typical one-to-many kind of way. Using Linq to NHibernate to query Bars accord...

Composite Key/Id Mapping with NHibernate

Hi, i have the following tables in my database: Announcements: - AnnouncementID (PK) - Title AnouncementsRead (composite PK on AnnouncementID and UserID): - AnnouncementID (PK) - UserID (PK) - DateRead Users: - UserID (PK) - UserName Note: Usually i'd map the AnnouncementsRead using a Many to Many relationship but this table also ha...

NHibernate - define fetching strategy dynamically

Let me explain the problem - hopefully I have defined it well in the title but I want to be sure. I have a linq query that pulls back a bunch of objects (say Foos). Each Foo holds a reference to a User. Each User holds a reference to a Person: public class Foo { //properties omitted... public User CreatedBy {get;} } public class Us...

Why do I need to set an alias to my projection if it's optional?

I'm reading the documentation about DetachedCriteria. The documentation clearly shows that setting an alias for your projection is optional. However, whenever I omit the alias my model properties contain no data. Here are my two test models. [ActiveRecord("INCIDENT")] public class Incident : ActiveRecordBase<Incident> { [PrimaryKey(...

Fluent NHibernate join not using primary key

I am trying to get a single property from a joined table where a non-PK in my main table is joined to the PK of the foreign table. Below is an oversimplified example of what I am trying to accomplish (I do not want to reference the foreign entity): Tables: CREATE TABLE Status ( Id int, Body text, CategoryId int ) CREATE TABLE C...

Using load-collection for an element with a composite key

Hi, I have two mappings, one with 2 named queries. Everything maps fine to the objects when I execute 2 separate repository calls - one for each object. The mappings for this are below: <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Company.Application.Models" assembly="Company.Application.Models"> <class name="Pro...

generator classes NHibernate

I have been using the generator class assigned to assign my primary key values. I have read several blogs which state that hilo is better. Is there a benefit to assigned over hilo? ...

Interceptor Castle/NHibernate general questions

I need some guidance on how the best way of adding interceptors to my project. I use Fluent NHibernate and Castle in my project and below is and example of what I would like to accomplish. public abstract class ContentItem { public virtual int? Id { get; set; } public virtual string Name { get; set; } public virtual IList<De...

When would Distinct(IEqualitComparer) be supported in NHibernate.Linq?

Hello SO Gus, This is a quick one! I've tried the latest v3.0.0 alpha and that overload of distinct is still not supported, however the parameterless overload (which uses the default equality comparer) is supported. Does anyone know when will this be supported in Nhibernate.Linq? Also is there any other Linq providers for NHibernate ...

API strategy of known .Net projects

I am writing an API for my application and have a few open questions (with versioning in mind). Should users call directly my objects or need I provide some abstraction? Should code that users wrote with version X of the API only work with version X or should it work also with the latest version? Initially I thought "abstraction" and...

NHibernate with schemaupadate and many-to-many

Is anybody knows how doesnt schemaupdate work with many-to-many e.g.: i have category and product entities with many-to-many on each one: how can i know when schemaupdate creates table: categoriesToProducts and when productsToCategories ps. i dont want to specify tableName in my mapping ...

AutoMapper limit depth of mapping or map lazily

Hello, AutoMapper is great, saves a lot of time, but when I started looking at the performance of my application AutoMapper is responsible for performance loss. I'm using lazy loading with NHibernate. Most of the time a need parent entity without needing to access child entities at all. In reality what happens is that AutoMapper tries ...

Pass Expression as a parameter into a Generic method, and plug the Expression into a CreateCriteria?

I have a generic method that exists in EntityRepository that gets entities by Name, which is defined as follows: public IEnumerable<T> GetEntitiesByName<T>(string searchExpression) where T : class, ISearchableEntity, new() { return _session.CreateCriteria<T>() .Add(LambdaSubquery.Property<Fun...

Fluent nHibernate - Map a list of strings

I have a model such as this (simplified) public class Post { public string ID { get; set; } public string Title { get; set; } public string Body { get; set; } public string AuthorName { get; set; } public List<string> Attachments { get; set; } } In my database, I have a Post table, and a PostAttachment table ...

nHibernate - SaveOrUpdate (no persistor for:)

I have an Abstract class: [Serializable] public abstract class BaseModel { public virtual int Id { get; private set; } public virtual DateTime? CreatedOn { get; set; } public virtual string CreatedBy { get; set; } public virtual DateTime? UpdatedOn { get; set; } public virtual string UpdatedBy { get; set; } publi...

How to have two mapping for the same table in Fluent nHibernate?

I have a User table defined like this: CREATE TABLE Users( UserId int IDENTITY(1,1) NOT NULL, UserName varchar(128) NOT NULL, Name nvarchar(200) NOT NULL, Password binary(64) NOT NULL, PasswordSalt binary(16) NOT NULL ) I'm trying to have two class that map to this table: The first object, called User has no Pass...

NHibernate Entities and Multiple Associations

I don't know how to phrase the question properly so sorry in advance. Using FluentNHibernate in particular, how would you go about making your entities for some tables that have are being referenced by a LOT of other tables? For example an Employee entity. Employees are generally used almost everywhere and it would make sense for some...

How to get a result based on Id with NHibernate.

I'm trying to get a Wrapper from NHibernate with the following code: public Wrapper GetWrapper(int siteId, string actionName) { Wrapper wrapper = _session.CreateCriteria<Wrapper>() //.Add(SqlExpression.Like<Wrapper>(xx => xx.SiteId, siteId)) .Add(SqlExpression.Equals(xx => xx.SiteI...