nhibernate

How to map uint in NHibernate with SQL Server 2005

你离开我真会死。 提交于 2020-01-11 09:10:30
问题 I have a property of type uint on my entity. Something like: public class Enity { public uint Count {get;set;} } When I try to persist that into the SQL Server 2005 database, I get an exception Dialect does not support DbType.UInt32 What would be the easiest way to workaround this. I could for example store it as long in the DB. I only don't know how to tell that to NHibernate. 回答1: The cleanest, most official solution would probably be to write a user type. Take an example, like this one and

NHibernate - Error dehydrating property value

淺唱寂寞╮ 提交于 2020-01-11 08:26:11
问题 I am getting the error Error dehydrating property value for while committing during update. I have searched and it looks similar to NHibernate: Error dehydrating property - What the heck is this? the only difference being that in the refered question NHibernate was complaining of Unable to resolve property Value for IssuingOffice is already existing in the database so it cannot be an issue of referencing an un-saved record The following is the detailed error. Test 'Tests.Services

NHibernate mapping not adding ON DELETE CASCADE option to foreign key reference

送分小仙女□ 提交于 2020-01-11 05:14:08
问题 Here's my NHibernate mapping. <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="HelloNHibernate" namespace="HelloNHibernate"> <class name="Showing" table="showing"> <id name="Id" column="showing_id"> <generator class="identity"/> </id> <many-to-one class="Theater" name="Theater" column="theater_id" foreign-key="fk_showing_theater_theater_id" cascade="delete" lazy="false" fetch="join"/> <many-to-one class="Movie" name="Movie" column="movie

Injecting ISession Into My Repositories Using Structuremap in a Asp.Net MVC Application

感情迁移 提交于 2020-01-10 15:40:13
问题 My repositories all take ISession in the constructor: protected Repository(ISession session) { this.session = session; } private readonly ISession session; In an Asp.Net MVC application, using StructureMap, how would I go about setting up ISession in my the StructureMap Registry? Would I need to to add SessionFactory to the container also? Does FluentNHibernate change things? 回答1: You should register ISession using a factory method. Another options (not always the best, but easy to use) is to

How to write custom nHibernate dialect?

徘徊边缘 提交于 2020-01-10 05:58:07
问题 I am using NHibernate with a legacy rdbms rule engine. I am using GenericDialect but some of the sql generated are not working. If I need to write custom Dialect for this rule engine how do start? 回答1: I would start by grabbing the nhibernate source, the 2.1.x branch is here. The existing Dialects are all under src/NHibernate/Dialect. Copy one and start hacking. The base class Dialect has many extension points. 回答2: This is an example dialect: using System; using System.Collections.Generic;

How do I get fluent nhibernate to create a varbinary(max) field in sql server

和自甴很熟 提交于 2020-01-09 07:53:03
问题 How can I get fluent nhibernate to create a varbinary field in a sql server 2005 table that uses a field size of varbinary(max)? At the moment I always get a default of varbinary(8000), which isn't big enough as i'm going to be storing image files. I've tried using CAstle.ActiveRecord but havent had any success yet. [ActiveRecord] public class MyFile : Entity { public virtual string FileName { get; set; } public virtual string FileType { get; set; } public virtual int FileVersion { get; set;

hibernate - createCriteria or createAlias?

ぐ巨炮叔叔 提交于 2020-01-09 06:20:51
问题 If I want to search those students who take class "Math" and "John" is his group: shoud I use createCriteria or createAlias? Criteria: Criteria criteria = session.createCriteria(Student.class); Criteria subquery1 = criteria.createCriteria("courses", course).add(Restrictions.eq(course.name, "Math")); Criteria subquery2 = criteria.createCriteria("group", student).add(Restrictions.eq(student.name, "John")); how to put subquery1 and subquery2 together with initial criteria? Alias: Criteria

hibernate - createCriteria or createAlias?

若如初见. 提交于 2020-01-09 06:18:08
问题 If I want to search those students who take class "Math" and "John" is his group: shoud I use createCriteria or createAlias? Criteria: Criteria criteria = session.createCriteria(Student.class); Criteria subquery1 = criteria.createCriteria("courses", course).add(Restrictions.eq(course.name, "Math")); Criteria subquery2 = criteria.createCriteria("group", student).add(Restrictions.eq(student.name, "John")); how to put subquery1 and subquery2 together with initial criteria? Alias: Criteria

Splitting NHibernate entity row storage across multiple tables

社会主义新天地 提交于 2020-01-07 05:40:13
问题 In our NHibernate setup, we have a Listing entity. For DB performance reasons, we want to split the storage of it into multiple tables, by country (the way the site is set up, no-one can ever search in more than one country at a time). So, Listing_US, Listing_FR, etc. Two questions, the first far more important than the second: Is there any way NHibernate can do this mapping for me? Presumably it would be based around an internal field that gets generated on the Get() (where I'd pass in the

Fluent NHibernate Many-to-many mapping with auto-generated pk instead of composite key

£可爱£侵袭症+ 提交于 2020-01-07 05:10:11
问题 I'm working on a RoleProvider in .NET, using Fluent NHibernate to map tables in an Oracle 9.2 database. The problem is that the many-to-many table connecting users and roles uses a primary key generated from a sequence, as opposed to a composite key. I can't really change this, because I'm writing it to be implemented in a larger existing system. Here is my UserMap: public UserMap() { this.Table("USR"); HasMany(x => x.Memberships).Cascade.All() .Table("MEMBERSHIP").Inverse().LazyLoad();