fluent-nhibernate

FluentNHibernate: How to handle one-to-many values when the many is a simple enum

It seems like the following scenario shouldn't be uncommon, but I can't figure out how to handle it in FluenNHibernate: public class Product: BaseEntity { public Product() { Categories = new List<Category>(); } public virtual IList<Category> Categories { get; set; } ... } public enum Categories { Classi...

Trouble Creating Specification Across Entities With NLinq

I am using the Specification pattern, and have a working implementation (taken from the WhoCanHelpMe Codeplex project) for getting data via NLinq, generic repositories and all that goodness. The root method is: public IList<Case> GetCasesByUsername(string username) { CaseByUserNameSpecification spc = new CaseByUserNameSpecification...

NHibernate query is not returning any results

I'm trying to get Fluent and NHibernate configured properly with ASP.NET MVC. As far as I know it's configured properly but when I access the page that uses this setup I am not receiving any data results. The model I'm using is called Brand and the database table is Brands. Here is a snippet from my BrandController: public ActionResul...

Creating a Virtual Many-To-Many Relationship with NHibernate

Let's say you have three entities - Categories, Sites and Items. The Items table has a CategoryID and a SiteID. If I want to find the sites for a given category, I can get that with a mapping in NHibernate that looks something like: public CategoryMap() { //.. ManyToMany(x => x.Site) .Table("Items") .ParentKey("CategoryID") ...

How to Map a VIEW without unique identifing column with Fluent Nhibernate

hi, i have readonly VIEWs in an existing Database and i'd like to get them with FHN. i tried mapping it the following way: public class HhstMap : ClassMap<Hhst> { public HhstMap() { Table("HHST"); ReadOnly(); Id(); Map(x => x.Hkz); Map(x => x.Kapitel); Map(x => x.Titel); ...

How to set discriminate column type for subclass with FNH?

What is the new SetAttribute() in FNH mapping? I need to set my discriminator value on subclass because String is not preferred - old post with NH 2.1.2.4000, FNH 1.1.0.689 public class BaseBuildingMap : ClassMap<BaseBuilding> { public BaseBuildingMap() { Id(x => x.Id); DiscriminateSubClassesOnColumn<int>("Build...

Fluent NHibernate - mapping an Entity as a different type

I have a class which I would like to map as a component onto any table which contains it: public class Time { public int Hours { get; set; } public int Minutes { get; set; } public int Seconds { get; set; } } I would like to store this class as a bigint in the database - the same as how TimeSpan is stored but my class has ...

NHibernate query cache not working after update to the database

I have enabled 2nd level cache in FluentNHibernate: Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005 .ConnectionString(connectionString) .Cache(c => c.ProviderClass<SysCacheProvider>().UseQueryCache()) ) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<PersonMap>())...

Fluent: has invalid child element 'many-to-one' in namespace

I'm trying to map myexisting database by Fluent NHibernate I get error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'many-to-one' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespa...

Sorting two columns using NHibernate Criteria API

I need to sort a result set by two columns, one of which is always NULL. A simplified view of Database where the columns I wish to sort on look like : ColumnA is from Table A Column B, B1 is from table B ColumnA ColumnB ColumnB1 U NULL NULL P NULL NULL L NULL NULL NULL U NULL NULL ...

NHibernate Log Tables to Track all Changes to a Table

Hi, i have the following db structure: Users: - UserID - UserName - FirstName - LastName ... UsersLog: - UserLogID - UserID - UserName - FirstName - LastName ... - DateCreated The log table simply inserts a record against the user everytime an insert or edit is made. The reason i have the log table is that when an order is submitted...

Using Entities from an Entity Framework (v3.5) Model with Fluent NHibernate

Hi all, Using Microsoft's designer for the Entity Framework (v3.5), I have created an Entity Model (*.edmx) with a generated *.Designer.cs class. I can persist my objects to MS SQL Server using the model without any problems. I am new to NHibernate, and out of curiosity, I now would like to use my model with Fluent NHibernate and SQL...

Using a reference as id in fluentnhibernate

I have a child table containing an id to the parent. This is a one to one mapping, but the child table might be missing values. I'm having problems mapping this without getting an error though... I've tried several things; mapping the same column, having distinct properties etc.. Parent table int id Child table int parentid Paren...

Is it possible for nhibernate to return a query as an IDictionary instead of an entity class?

I have an entity Person: public class Person { public virtual int Id {get; set; } public virtual string FirstName { get; set; } public virtual string MiddleName { get; set; } public virtual string LastName { get; set; } } with the mappings: public class PersonMap { public PersonMap() { Table(TABLE_NAME); ...

Prevent NHibernate from aliasing in ORDER BY

I have a query which has an Order By clause. The generated SQL from NHibernate looks like ORDER BY coalesce(x.Company as x__.Company, y.Company) asc This fails as 'as' is not allowed in Order by clause in MS SQL Server. Is there any way I can prevent aliasing? The criteria query that I have written looks like: var orderBy = Proj...

fluent-nhibernate automapping foriegn key inserts null.

I have a class called Worker public class Worker : BaseEntity { public virtual int WorkerID { get; set; } public virtual string Name { get; set; } public virtual IList<Indemnification> Indemnifications { get; set; } } public class Indemnification : BaseEntity { public virtual int IndemnificationID { get; set; } pu...

Getting multiple queries when transaction is committed, why?

public Parent GetByName(string Name) { return _session.CreateCriteria<Parent>() .Add(Restrictions.Eq("Name", Name)) .SetFetchMode("Children", FetchMode.Eager) .SetResultTransformer(new DistinctRootEntityResultTransformer()) .UniqueResult<Parent>(); } public ParentDetailVM GetMeAParent(string Name) { ...

How do I delete a record?

I'm trying to delete a database record using ASP.NET MVC, Fluent, and NHibernate. See the code below for examples of how I'm trying to accomplish this. I am able to Get, Update, and Insert records but Delete is not working. When the Delete() method gets called in the controller (top one) it throws an Exception (System.Data.SqlClient.SqlE...

i need NHibernate.ByteCode.Castle source code

Hi I need to get into FluentNhibernate and NHibernate code so i rebuild the solutions and used the new assemblies, but the problem is that there is an assembly called NHibernate.ByteCode.Castle.Dll which refuses to load the my own version of Nhibernate and keep telling me that the Public Token doesn't match, so where can i get the sour...

Is there a FluentNHibernate provider for Active Directory?

I would like to use FluentNHibernate to map an Active Directory user object to a POCO object but can't find a provider in the FluentNHibernate.Cfg.Db namespace that will allow me to setup the connection. This is the data layer of a WCF RIA Service. Is there a way to do this? ...