fluent-nhibernate

Fluent NHibernate one-to-many relationship setting foreign key to null

∥☆過路亽.° 提交于 2019-12-09 13:05:22
问题 I have a simple Fluent NHibernate model with two related classes: public class Applicant { public Applicant() { Tags = new List<Tag>(); } public virtual int Id { get; set; } //other fields removed for sake of example public virtual IList<Tag> Tags { get; protected set; } public virtual void AddTag(Tag tag) { tag.Applicant = this; Tags.Add(tag); } } public class Tag { public virtual int Id { get; protected set; } public virtual string TagName { get; set; } public virtual Applicant Applicant {

Fluent Nibernate putting a where clause in the mapping

守給你的承諾、 提交于 2019-12-09 12:59:08
问题 I've got two objects a parent and a child list. In my fluent nhibernate mapping for the parent I want to load the list of the children. However I want this to be conditional, a column in the child table is called "IsDeleted" and I only want to return the children where "IsDeleted" is false. Is it possible to set up a mapping to do this? If not is it possible to do it in just standard nhibernate? Thanks 回答1: Yes, you can use a Where constraint in Fluent NHibernate to map this. Somehting like:

How can I use Fluent NHibernate Automapping with multiple Lists of the same type in an Entity?

人走茶凉 提交于 2019-12-09 12:02:41
问题 It appears that NHibernate cannot automap more than one IList of a given type in an entity. Consider the following two entities (based on the Examples.FirstProject sample code that is included with the Fluent NHibernate source code). public class Employee { public virtual int Id { get; private set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } } public class Store { public virtual int Id { get; private set; } public virtual IList<Employee> Staff

Quoting column names with NHibernate and PostgreSQL

一个人想着一个人 提交于 2019-12-09 05:54:26
问题 I have started to use NHibernate 3.0 and PostgreSQL for a small project, so far the ride has been a little rough due to the NHibernate site being down and I'm sure this answer is on their website somewhere. I have a database that has these two columns(of course there is more in the real table): int ID String Feature now I'm using a FluentNHibernate to do the mapping so something like this: public class MyEntityMap: ClassMap<MyEntity> { public MyEntityMap() { Id(x => x.ID); Map(x => x.Feature)

Problem with linq query

送分小仙女□ 提交于 2019-12-09 05:02:29
问题 I'm trying to use linq to NHibernate (with Fluent NHibernate) but I have problems with linq query. Everytime I try to execute it I get this message : " Method 'get_IsReadOnlyInitialized' in type 'NHibernate.Linq.Util.DetachedCriteriaAdapter' from assembly 'NHibernate.Linq, Version=1.1.0.1001, Culture=neutral, PublicKeyToken=null' does not have an implementation. " Does anybody know how to fix this problem? I tried with solution form this page with model context but it didn't help. This is the

Nhibernate producing proxy despite HQL fetch

一曲冷凌霜 提交于 2019-12-09 01:54:21
问题 I have the following HQL statement: select distinct t from TaskEntity as inner join fetch t.Case as c inner join fetch c.Client as client inner join fetch c.Matter as matter However, despite Matter having a FETCH against it, it's still returning as a proxy. My mapping for this object is below References(x => x.Matter).Columns(new[] {"c_client","c_matter" }); I've tried using JOIN on this, but my issue I'm going from 1 to 2 columns, so it wouldn't accept the mapping. Any thoughts? Thanks, 回答1:

Nhibernate 2nd level caching issues / questions when moving from a single web server to a multiple web server load balanced environment

有些话、适合烂在心里 提交于 2019-12-08 18:21:21
问题 My previous setup was a single web server and a single database server. I was using nhibernate 2nd level caching to cache stuff to avoid lots of calls going to the database. This has worked great as i was using this this assembly nhibernate.caches.syscache and added this code to turn on the second level caching (using the regular syscache provider): return configuration .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ApplicationMap>().Conventions.Add(typeof(Conventions)))

Can you specifiy the identity column when using the Fluent Nhibernate Table-Per-Subclass strategy?

有些话、适合烂在心里 提交于 2019-12-08 17:40:20
问题 I am creating a Fluent N hibernate subclass mapping that currently looks something like this: public class TaskDownloadMap: SubclassMap<TaskDownload> { public TaskDownloadMap() { Table("TasksDownload"); Map(x => x.ExtraProperty1, "ExtraProperty1") .Nullable(); Map(x => x.ExtraProperty2, "ExtraProperty2") .Nullable(); } } When I try and save one of these entities I get an exception: Test.TaskRepositoryTest.DeleteTest: NHibernate.Exceptions.GenericADOException : could not insert: [TaskManager

NHibernate: Default value for a property over a null column

萝らか妹 提交于 2019-12-08 16:58:28
I'm working with an old database used by other applications, so i can't modify its structure. Sometimes i have nullable columns that i want to map as a non nullable type. For instance I have a nullable EndValidity column on database which i want to map on a non nullable DateTime, and, if null, it should be DateTime.MaxValue, or as a more simple example, a nullable bit column that must be false if null. I'm thinking about writing a custom user type for it (with parameters if possible), or is it there something included in nHibernate for it? If the only solution is to write a custom usertype,

NHibernate emitting extraneous update statements regardless of proper Inverse (fluent nhibernate) settings on relations

只谈情不闲聊 提交于 2019-12-08 16:53:14
问题 The following classes represent, in a bare-minimum way, my real-world scenario with a legacy database. I can add new columns to it, but this is all I can do, since the 300+ hundred table database is used by many other legacy applications which won't be ported to NHibernate (so migrating from composite keys isn't an option): public class Parent { public virtual long Id { get; protected set; } ICollection<Child> children = new HashSet<Child>(); public virtual IEnumerable<Child> Children { get {