fluent-nhibernate-mapping

NHibernate exception: could not initialize a collection, Invalid column name. Fluent mapping. Maybe a many-to-one issue?

馋奶兔 提交于 2019-12-05 12:42:45
I am puzzled and frustrated by an exception I'm getting via NHibernate. I apologize for the length of this post, but I've tried to include an appropriate level of detail to explain the issue well enough to get some help! Here's the facts: I have a Person class which contains a property BillingManager , which is also a Person type. I map this as an FNH "Reference". I have an ExpenseReport class which contains a property SubmittedBy , which is a Person type. I map this as an FNH "Reference". I have a BillableTime class which contains a property Person , which is a Person type. I map this as an

NHibernate - Force escaping on Table Names

a 夏天 提交于 2019-12-05 08:38:54
Are there any good examples of how to use this (NHibernate.Criterion.IdentifierEqExpression) online? I couldn't find any. I'm a little confused about what you are supposed to pass into the constructor. I pass in an int32 of 1 and I keep thinking my test should basically do a "where id = 1" type of query and instead it blows up with "where id = ?" and something about positional parameters. If that's not what is supposed to be passed into the constructor ... what is? Real Issue When I look at SQL output it seems to be working correctly except for the fact my table is named User and NHibernate

NHibernate map one-to-many relationship with intermediate table

女生的网名这么多〃 提交于 2019-12-04 14:20:41
问题 How to define mapping without intermediate class PostTag creation? I have three tables t_post(id...) t_tag(id, name) t_post_tag(id,post_id, tag_id) I want to have a collection with Tags in Post type classes: class Post { public virtual IEnumerable<Tag> Tags{ get; set; } } public class Tag { } mappings: <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping assembly="Sample.Core" namespace="Sample.Core.Domain.Model" xmlns="urn:nhibernate-mapping-2.2"> <class name="Post" table="t_post" lazy=

Fluent NHibernate References with constants

不想你离开。 提交于 2019-12-04 10:02:20
I have a table mapped in Fluent NHibernate. This table must join to another table on an ID, but must also filter the joined values on that table against a set of constant values. Consider the following SQL: SELECT * FROM Table1 INNER JOIN Table2 ON Table1.Table2Id = Table2.Id AND Table2.Category = 'A constant expression' AND Table2.Language = 'A constant expression' My fluent mapping for Table1 currently looks like this: References(a => a.Table2).Nullable().Columns("Table2Id").ReadOnly(); How can I implement the constant expressions? I have noticed that your mapping specifies Nullable and no

NHibernate Fluent Add external Assembly mappings

落爺英雄遲暮 提交于 2019-12-04 06:49:24
问题 I have a project with my mappings and entities stored in other class libraries and NHibernate layers in another project. In my testing project I would like to add these mapping via fluently configure... Mappings... via assebly and not individually. In my code below you can see I added just one entity.. But I would like to configure it to scan my other assemblies. I am sure I am just missing the obvious here.. any pointers would be greatly appreciated... [Test] public void Can_generate

Fluent NHibernate One-To-Many Mapping

旧街凉风 提交于 2019-12-04 03:54:14
I have the following 2 classes: Advert public virtual int Id { get; set; public virtual IList<AdvertImage> AdvertImages { get; set; } AdvertImage public virtual int Id { get; set; } public virtual string Filename { get; set; public virtual Advert Advert { get; set; } In the DB, my AdvertImages table has the FK 'AdvertId' which relates to the Adverts table which has the PK of 'Id'. This is a One-To-Many mapping, in that one advert can have many images. My Fluent NHibernate mappings (edited for brevity) are: AdvertMap Id(x => x.Id) .GeneratedBy.Identity(); ... HasMany(x => x.AdvertImages)

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

自古美人都是妖i 提交于 2019-12-03 15:52:35
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 { get; set; } } My fluent mapping is the following: public class ApplicantMap : ClassMap<Applicant> {

Fluent NHibernate HasMany Foreign Key Mapping Problem

可紊 提交于 2019-12-03 12:49:44
问题 I'm trying to map a simple data structure in nhibernate Tables: Employees employeeID int username varchar(30) departmentID int Departments departmentID int deptName varchar(50) My department mapping is like so: public class DepartmentMap: ClassMap<Department> { public DepartmentMap() { Id(m => m.DepartmentID).Column("departmentID"); Map(m => m.DepartmentName).Column("deptName").Length(50); HasMany(m => m.Employees); Table("Departments"); } } ... and the employee mapping public class

Fluent Nhibernate Many to Many Mapping Way

江枫思渺然 提交于 2019-12-03 11:40:20
问题 I have two classes Order and Items I want a method like this class Order { public virtual IList<Item> GetItems(Order order) { //get items for that order. } } class Item { public virtual IList<Order> GetOrders(Item item) { //get all the orders in which that items is present. } } Is it write to create a method like this or instead should I create a property public virtual IList<Item> Items { get; set; } And how should I do the mapping for this is nhibernate?? 回答1: Apparently you have a many-to

Fluent NHibernate generates extra columns

别来无恙 提交于 2019-12-03 09:25:27
问题 We are using Fluent NHibernate for data object model in the company i work. A couple of days ago, we encountered an issue that Fluent NHibernate generates an extra column which does exist neither in model nor in mapping. Here is the situation: My Model: FirstClass.cs public class FirstClass { public virtual int Id { get; private set; } public virtual SecondClass MyReference { get; set; } public virtual DateTime DecisionDate { get; set; } } My Mapping: public class FirstClassMap : ClassMap