fluent-nhibernate

Null value objects in NHibernate

假如想象 提交于 2019-12-22 03:45:38
问题 I have a person entity containing an Address as a value object: public Person() { WithTable("Person"); Id(x => x.Id); Component<Address>(x => x.Address, a => { a.Map(x => x.Address1); a.Map(x => x.Address2); a.Map(x => x.Address3); a.Map(x => x.Town); a.Map(x => x.Postcode); }); } It states in the NHibernate docs that if all the properties of a value object (Address1, Address2 etc) are null, the entire component will be mapped as null (i.e. Person.Address will be null). This is giving me

Fluent nHibernate automapping property as nvarchar(max)

安稳与你 提交于 2019-12-22 03:24:36
问题 using fluent nhibernate, and automappings (nhibernate creates my db schema), how can i get nhibernate to create a nvarchar(max) column in the database based on the following class public class VirtualPage : BaseEntity { public virtual int ParentId { get; set; } public virtual string PageName { get; set; } public virtual string Title { get; set; } public virtual string Body { get; set; } public virtual string ViewName { get; set; } public virtual string ViewData { get; set; } // this must be

NHibernate Image Storage - The length of the byte[] value exceeds the length configured

ぐ巨炮叔叔 提交于 2019-12-22 03:24:30
问题 I am using Fluent NHibernate and am trying to store an image. Small images work, but larger images do not, and I receive this error when saving to the database (SQL Server): Exception: Error dehydrating property value for CFC.Domain.Vehicle.Image Inner Exception: The length of the byte[] value exceeds the length configured in the mapping/parameter. Here is my mapping: mapping.Table("Vehicle"); mapping.Id(x => x.Id, "VehicleID"); mapping.Map(x => x.Year).Not.Nullable(); mapping.Map(x => x

NHibernate paging criteria with fetchmode eager. (using fluent NH)

断了今生、忘了曾经 提交于 2019-12-22 00:29:31
问题 Question: How to get an eager loaded criteria to return paged results on the root entity with all child collections set fetchmode = eager. I am trying to get a 10 item paged result set with eager loaded child collections. The problem is the query does a select top 10 wrapped around the entire select. The causes it to return only the first 10 results including all joined records. If the first entity has 10 child objects then my result set will return 1 entity with 10 child objects loaded. I

Fluent NHibernate and filtering one-to-many relationship on query requiring multiple joins?

安稳与你 提交于 2019-12-21 20:48:47
问题 I recently got started with NHibernate and am having some trouble implementing the domain model outlined further down. What I'm looking for is a way to filter the relationship between an Item and it's ItemData collection on specific DataStores. DataStores are either global, in which case they are always returned, or specific to a user identity (based on application instance). In SQL this can be accomplished using a simple query: SELECT * FROM Items i INNER JOIN ItemData id ON (i.ItemId=id

FluentNhibernate, add mappings from multiple assemblies

你。 提交于 2019-12-21 19:44:51
问题 I've tried to add mapping classes manually, by using multiple .Mappings extension calls, but it seems only to include the last one. So how do I add several selected class maps, or multiple assemblies? My fluent configuration looks typically like this: Return Fluently.Configure() _ .Database(SQLiteConfiguration.Standard.ConnectionString(connectionString) _ .Cache(Function(c) c.UseQueryCache())) _ .Mappings(Function(m) m.FluentMappings.AddFromAssemblyOf(Of AccountMap)() _ .Conventions.Add

Using custom type for the id property

那年仲夏 提交于 2019-12-21 18:03:55
问题 I got the following classes: public class UserId { public UserId(int id){ //some validation } public override string ToString() {} } public class User { public UserId Id {get;set;} } How can I configure nhibernate/fluentnhibernate to use that class. The column is an int. 回答1: as Diego mentioned it is not nessesaryly a good idea // UserMap Id(m => m.Id).CustomType<UserIdUserType>(); class UserIdUserType : IUserType { ... } 来源: https://stackoverflow.com/questions/9444056/using-custom-type-for

Fluent NHibernate - HasMany().WithKeyColumnName

橙三吉。 提交于 2019-12-21 17:58:20
问题 I just got the latest version of Fluent from Google code and it seems some of the mapping has changed since I last used it. Previously I could Map a relationship using the following when the id I was joining on had a different name in the second table HasMany(x => x.Roles).WithTableName("tbl_Roles").WithKeyColumn("RoleId"); How is done in the latest release of Fluent? Thanks 回答1: HasMany(x => x.Roles) .WithTableName("tbl_Roles") .KeyColumns.Add("RoleId"); Multiple column support was added, so

Fluent NHibernate - HasMany().WithKeyColumnName

巧了我就是萌 提交于 2019-12-21 17:57:12
问题 I just got the latest version of Fluent from Google code and it seems some of the mapping has changed since I last used it. Previously I could Map a relationship using the following when the id I was joining on had a different name in the second table HasMany(x => x.Roles).WithTableName("tbl_Roles").WithKeyColumn("RoleId"); How is done in the latest release of Fluent? Thanks 回答1: HasMany(x => x.Roles) .WithTableName("tbl_Roles") .KeyColumns.Add("RoleId"); Multiple column support was added, so

Fluent NHibernate References with constants

风流意气都作罢 提交于 2019-12-21 17:49:05
问题 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