nhibernate-mapping

HasOne vs References Mapping Fluent NHibernate

不羁岁月 提交于 2020-01-01 02:53:06
问题 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

Fluent NHibernate + multiple databases

旧巷老猫 提交于 2020-01-01 02:41:27
问题 My project needs to handle three databases, that means three session factories. The thing is if i do something like this with fluent nhibernate: .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly())) the factories would pick up all the mappings, even the ones that correspond to another database I've seen that when using automapping you can do something like this, and filter by namespace: .Mappings(m => m.AutoMappings.Add( AutoMap .AssemblyOf<Product>() .Where(t => t

NHibernate - Wrong Columns on Queries

北慕城南 提交于 2019-12-31 22:21:36
问题 I'm getting an intermittant problem with NHibernate where it generates a query for an entity, but replaces one of the columns with a column from completely different (and unrelated) entity. It only ever replaces a single column, and is generally solved by restarting the application (though sometimes it takes a couple of attempts). ASP.NET application (.NET 4.0) SessionFactory created during Application_Start NHibernate 3.3.1- All mappings/configuration done via Mapping By Code Using

NHibernate mapping problem - Could not initialize proxy - no Session

拈花ヽ惹草 提交于 2019-12-31 05:25:12
问题 I have just started to learn NHibernate, and are following tutorials. On my own learning project, I have made up a problem for myself. I have two tables: Team: TeamId* Name Match: MatchId* TeamAId TeamBId The model entities are: Team public virtual int? TeamId { get; private set; } public virtual string Name { get; set; } public virtual IList<Match> HomeMatches { get; set; } public virtual IList<Match> AwayMatches { get; set; } Match public virtual int? MatchId { get; private set; } public

Exclude property from INSERT command in nhibernate

笑着哭i 提交于 2019-12-31 02:28:12
问题 I have an entity with a property which I wish to be readonly - meaning that when I insert this entity to the DB, SqlServer will generate the property's value automatically so I need nhibernate to ignore this property when executing the INSERT command but retrieve it when selecting the entity. Important note: this property isn't ID ! I don't want NHibernate to initialize it using generator, SqlServer will do it by itself. And another note: I use configuration mapping so no fluent mapping

Strategies for Mapping Views in NHibernate

一曲冷凌霜 提交于 2019-12-30 08:26:16
问题 It seems that NHibernate needs to have an id tag specified as part of the mapping. This presents a problem for views as most of the time (in my experience) a view will not have an Id. I have mapped views before in nhibernate, but they way I did it seemed to be be messy to me. Here is a contrived example of how I am doing it currently. Mapping <class name="ProductView" table="viewProduct" mutable="false" > <id name="Id" type="Guid" > <generator class="guid.comb" /> </id> <property name="Name"

Inner or Right Outer Join in Nhibernate and Fluent Nhibernate on Many to Many collection

馋奶兔 提交于 2019-12-30 06:39:28
问题 How can I force NHibernate to do a RIGHT outer join or an INNER join instead of a LEFT outer join on a many to many collection? The reason I would want to do this is because of filtering applied to the collection elements. With a left join, you get the same number of rows returned as an unfiltered query, but the elements that are filtered out just show NULL for all of the fields. However, with a right join, the correct number of rows and elements are returned from the query. I would expect

Fluent NHibernate Many to one mapping

筅森魡賤 提交于 2019-12-30 04:55:09
问题 I am new to Hibernate world. It may be a silly question, but I am not able to solve it. I am testing many to One relationship of tables and trying to insert record. I have a Department table and Employee table. Employee and Dept has many to One relationship here. I am using Fluent NHibernate to add records. All codes below. Pls help SQL Code create table Dept ( Id int primary key identity, DeptName varchar(20), DeptLocation varchar(20) ); create table Employee ( Id int primary key identity,

Prevent Nhibernate schemaexport from generating foreign key constraints on has many relationship

社会主义新天地 提交于 2019-12-29 05:18:26
问题 I have a mapping like this: HasMany(x => x.Orders).KeyColumn("CustomerID"); Which is causing a constraint like this to be generated by schemaexport: alter table [CustomerOrder] add constraint FK45B3FB85AF01218D foreign key (CustomerID) references [Customer] I have tried adding .NotFound.Ignore() like on a References() mapping to disable the constraint from being generated but this does not work. Can a mapping be defined that will force SchemaExport to not generate the constraint? 回答1: Figured

How to create a Multi-Column Index or Unique Constraint with NHibernate

非 Y 不嫁゛ 提交于 2019-12-28 05:51:45
问题 How to create a Multi-Column Index and/or Unique Constraint using NHibernate Mapping or Fluent NHibernate. 回答1: assign a index/unique constraint name to more then one property <property name="A" index="AB" /> <property name="B" index="AB" /> Theoretical it would also work with having more then one index on the same entity: <property name="A" index="AB, ABC" /> <property name="B" index="AB, ABC" /> <property name="C" index="ABC" /> But there is a bug. I also wrote a patch. if you are