nhibernate-mapping

Fluent NHibernate and computed properties

拜拜、爱过 提交于 2019-12-19 09:05:17
问题 I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in a class along the lines of public virtual DateTime? LastActionTimeStamp { get { return Actions.Count == 0 ? null : Actions.OrderByDescending( a => a.TimeStamp).ElementAt(0).TimeStamp; } } This wasn't mapped with the rest of the properties, so I couldn't use it in an ICriteria restriction. I added an empty setter (as I read somewhere that doing so would include it in the mapping, which it does), but now I

NHibernate Join Fetch(Kind)

一世执手 提交于 2019-12-19 07:18:33
问题 Given a Team -> Athlete relationship and querying all athletes. What am I misunderstanding about fetch="Join" ? Should this mapping cause the Team to be loaded via a join? When iterating the athletes, it still lazy loads the Team. public class AthleteMap : ClassMapping<Athlete> { public AthleteMap() { ManyToOne(a => a.Team, o => { o.Fetch(FetchKind.Join); o.Lazy(LazyRelation.NoLazy); } ); } } Which produces this HBM: <class name="Athlete" table="Athletes"> <id name="Id" type="Int32" />

Fluent-Nhibernate References and PropertyRef Doing a Select With Lazy Load

耗尽温柔 提交于 2019-12-19 04:06:24
问题 I am using PropertyRef for one of my References properties. With LazyLoad() it still does a Select and loads the User entity, even though I never "hit" the SalesPerson property. Order Mapping Id(x => x.Id).GeneratedBy.Native(); References(x => x.SalesPerson) .LazyLoad() .PropertyRef(x => x.Username) .Column("rsm"); Map(x => x.Title); Order Class public class Order : BaseEntity { ... public virtual User SalesPerson { get; set; } public virtual string Title { get; set; } ... } User Mapping Id(x

Using Additional Data on Intermediate Table with NHibernate

丶灬走出姿态 提交于 2019-12-18 09:26:48
问题 I'm working on a project that is used to input information about a product into a document. One section has a form that can be filled out as many times as needed for a particular product. The information on this form is then available to be shared on multiple related documents. A typical many-to-many situation. The difference is, on the intermediate table, I want to store specific information for that form entry for that specific document. Here are some table definitions to illustrate the

NHibernate force not-found ignore to not execute an extra select

删除回忆录丶 提交于 2019-12-18 06:58:32
问题 I'm working with a legacy database where FK's aren't always used. For example I have an entity Person and an entity Country. A person has a Country which is mapped as a many-to-one in the Person mapping. <many-to-one name="Country" class="Country" foreign-key="none" lazy="false" not-found="ignore" fetch="join" outer-join="true" column="countryid"/> When person has null as column value (countryid) it won't perform an extra select query (because it knows that there won't be a reference in the

How to create composite UNIQUE constraint in FluentNHibernate?

天涯浪子 提交于 2019-12-18 05:28:33
问题 I know that I can Map(x => x.GroupName).WithUniqueConstraint() for a single property. But how do create a composite unique constraint in fluent nHibernate (where the unique constraint operates on the combination of two columns)? 回答1: In the latest version that I have used, it is UniqueKey("KeyName") that does this. Map(x => x.Something).UniqueKey("KeyName"); Map(x => x.SomeOtherThing).UniqueKey("KeyName"); 回答2: Use SetAttribute in your mapping file like so: Map(x => x.Something).SetAttribute(

Query Unmapped Columns in NHibernate

↘锁芯ラ 提交于 2019-12-18 03:38:11
问题 I have a class that is mapped to a table using NHibernate. The problem is that only some of the properties are mapped to columns in the table. This is fine because the only columns we use for display are mapped, however I was wondering if there is any way to query against other columns in the table that aren't mapped to properties in my class. For example we have a table with the following columns: Customer ----------- CustomerId Name DateCreated and we have an object public class Customer {

How to map IDictionary<string, Entity> in Fluent NHibernate

大城市里の小女人 提交于 2019-12-18 03:37:13
问题 I have an class with an IDictionary on it. <map name="CodedExamples" table="tOwnedCodedExample"> <key> <column name="OwnerClassID"/> </key> <index type="string" column="ExampleCode"/> <many-to-many class="CodedExample" column ="CodedExampleClassID"/> </map> as you can see it uses a many-to-many to get the CodedExamples from their table using the tOwnedCodedExample table to find which are owned by the OwnerClass. I realise that this is a very basic (and hopefully standard) mapping but am

nHibernate 2.0 - mapping a composite-id *and* many-to-one relationship causes “invalid index” error

被刻印的时光 ゝ 提交于 2019-12-18 03:05:24
问题 I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag] table has: TagId, TagDescription [PersonTag] has: PersonId, TagId, IsActive Since [PersonTag] isn't just a simple many-to-many join table, I have all three entities created in nHibernate (exactly like they are in the data model). PersonTag , therefore, needs a composite-id, which I have mapped to a class like this: <composite-id name="PersonTagKey" class="PersonTagKey"> <key-property name="PersonId"></key

NHibernate - How to store UInt32 in database

和自甴很熟 提交于 2019-12-17 21:35:02
问题 What is the best way to map UInt32 type to sql-server int type with NHibernate. The value is a picture width/height so negative value are not make sense here. But maybe I should use int because NHibenate doesn't support unassigned ints. 回答1: You can map the column with an IUserType. <class name="UnsignedCounter"> <property name="Count" type="mynamespace.UInt32Type, mydll" /> </class> And the IUserType which maps UInt32? and UInt32 . class UInt32Type : IUserType { public object NullSafeGet(