fluent-nhibernate

Fluent NHibernate mapping on multiple non-PK fields

烂漫一生 提交于 2019-12-03 08:05:56
I have a situation similar to that described in Fluent NHibernate Mapping not on PK Field However, the relationship between my tables is described by multiple non-primary key columns. Imagine Chris Meek's situation but where a Person has a JobType and a Code that, together, should (sorry, it's a legacy database) uniquely describe a Person Person ------ Id PK JobType Code Name Order ----- Id PK Person_JobType Person_Code OrderDetails Serhat Özgel's answer describes using PropertyRef , but I can't find a way to do that individually for multiple columns. I've tried similar to class PersonMap :

Struggling to Comprehend nHibernate SchemaUpdate, even with Blog Posts

痴心易碎 提交于 2019-12-03 07:51:53
I've seen the various blog posts concerning nHibernate's SchemaUpdate , and even Ayende's very good example, and downloaded the samples, but for some reason I cannot get the same same thing to work for me. I will note that I am using Fluent NHibernate , but from what I can tell that should not make too huge a difference. Update I have reached the point where the SchemaUpdate runs, but it is just a full schema creation, no 'altering'. In otherwords, it's the same as if I just built the database fresh. I am posting my full source below. Here Is what I am basically trying... I think it is

Fluent NHibernate Self Referencing Many To Many

允我心安 提交于 2019-12-03 07:33:30
I have an entity called Books that can have a list of more books called RelatedBooks. The abbreviated Book entity looks something likes this: public class Book { public virtual long Id { get; private set; } public virtual IList<Book> RelatedBooks { get; set; } } Here is what the mapping looks like for this relationship HasManyToMany(x => x.RelatedBooks) .ParentKeyColumn("BookId") .ChildKeyColumn("RelatedBookId") .Table("RelatedBooks") .Cascade.SaveUpdate(); Here is a sample of the data that is then generated in the RelatedBooks table: BookId RelatedBookId 1 2 1 3 The problem happens when I Try

FluentNHibernate filter with parameterized IN clause

狂风中的少年 提交于 2019-12-03 07:17:10
In Fluent NHibernate, is it possible to add a parameter to a filter of type List<int> so that the filter condition generates a WHERE SomeColumn IN (@x, @y, @z) ? My use case is to fetch an invoice and a subset of its lines, given the ID of the invoice and a list of invoice line numbers. I want to eager fetch the lines in the same roundtrip as the invoice. I assume it is done something like this, but I cannot find the correct type declaration for the parameter type: Domain objects: public class Invoice { public int Id {get;set;} public List<InvoiceLine> Lines {get;set;} } public class

Error with hilo in NHibernate - “could not read a hi value - you need to populate the table”

筅森魡賤 提交于 2019-12-03 07:14:48
I've genereated a schema for my (SQL 2005) db using SchemaExport, and it's created a table CREATE TABLE [dbo].[hibernate_unique_key]( [next_hi] [int] NULL ) ON [PRIMARY] When I try to add an entity, I get the error "could not read a hi value - you need to populate the table". What am I meant to do? edit: I've inserted a 1 into the table, and it seems to work. Is this the correct value to have in there? NHibernate expects to find a value that stores the current hi value in that table, ie it first runs something like: current_hi = [SELECT max(next_hi) FROM hibernate_unique_key]. So all you need

FluentNHibernate Many-To-One References where Foreign Key is not to Primary Key and column names are different

浪子不回头ぞ 提交于 2019-12-03 07:10:23
I've been sitting here for an hour trying to figure this out... I've got 2 tables (abbreviated): CREATE TABLE TRUST ( TRUSTID NUMBER NOT NULL, ACCTNBR VARCHAR(25) NOT NULL ) CONSTRAINT TRUST_PK PRIMARY KEY (TRUSTID) CREATE TABLE ACCOUNTHISTORY ( ID NUMBER NOT NULL, ACCOUNTNUMBER VARCHAR(25) NOT NULL, TRANSAMT NUMBER(38,2) NOT NULL POSTINGDATE DATE NOT NULL ) CONSTRAINT ACCOUNTHISTORY_PK PRIMARY KEY (ID) I have 2 classes that essentially mirror these: public class Trust { public virtual int Id {get; set;} public virtual string AccountNumber { get; set; } } public class AccountHistory { public

HasOne vs References Mapping Fluent NHibernate

允我心安 提交于 2019-12-03 07:05:45
This is the first time I am working with FluentNhibernate Mapping and facing a question of how to reference another table. Any help is appreciated: I have several tables named CD_ varname and all these contain two columns - CODE and DESCR. I have one main table called Recipient and it has, say two columns, called ALIVE and SEX, both are of type number, and they reference to the tables CD_ALIVE and CD_SEX. If Alive=1 in the Recipient, then we need to get the code and descr from CD_ALIVE table where Code=1. I have described a Codef class: public Class Codef { int Code { get; set; } string Descr

NHibernate: Using Fluent Nhibernate to save child objects

末鹿安然 提交于 2019-12-03 06:38:40
问题 In my system, I have two entities - ShoppingCart and ShoppingCartItem. Fairly generic use-case. However, when I save my ShoppingCart, none of the items are being saved to the DB. Within my object, I create a new ShoppingCart object. ShoppingCart cart = CreateOrGetCart(); I then add an existing Product which I got from the database to the start. cart.AddItem(product); This is just a simple wrapper to add the item to the IList. public virtual void AddItem(Product product) { Items.Add(new

How do I handle table relationships with the repository pattern?

假如想象 提交于 2019-12-03 06:38:10
I'm implementing the repository pattern as part of an ASP.NET MVC site. Most examples I've seen of repositories are fairly simple. For example here's a typical abstract repository interface. public interface IRepository<TEntity> { IQueryable<TEntity> All(); TEntity FindBy(int id); TEntity FindBy(Expression<Func<TEntity, bool>> expression); IQueryable<TEntity> FilterBy(Expression<Func<TEntity, bool>> expression); bool Add(TEntity entity); bool Update(TEntity entity); bool Delete(TEntity entity): } It's clear to me how you would use a repository like this to add, update, delete, or get entities

Help with QueryOver and WhereExists

允我心安 提交于 2019-12-03 06:36:19
I have a problem. I have Persons and Cats. Each Person has some Cats (there is a foreign key in Cats that points to the primary key in Persons). Each Cat has an Age. I want to select the Persons that have "Old" Cats. I want ALL the Cats of these persons, and not only the "Old" Cats. I need to do it with the QueryOver syntax. In T-SQL it would be something like: SELECT P.*, C.* FROM Persons P LEFT JOIN Cats C ON P.Id = C.OwnerId WHERE EXISTS ( SELECT 1 FROM Cats C2 WHERE P.Id = C2.OwnerId AND C2.Age > 5) I know I have to use the subqueries, and I could to easily with the "old" nhibernate syntax