nhibernate-mapping

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 - Updating a table with a trigger on it causes an error - Unexpected row count: 2; expected: 1

痴心易碎 提交于 2019-12-22 01:25:25
问题 So I'm trying to update an object in my MS SQL 2005 database using NHibernate. Please keep in mind that this is a legacy database used in many live systems and I can't remove the triggers. When my data provider tries to .SaveOrUpdate() a row I get two returns (one for the actual update, and one when the trigger executes) The raw return looks like this: (1 row(s) affected) (1 row(s) affected) NHibernate then throws an exception like this: "Unexpected row count: 2; expected: 1" I'm essentially

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

NHibernate many-to-many relationship question: can select, can't update

ε祈祈猫儿з 提交于 2019-12-21 23:12:03
问题 Each user has a list of roles: <class name="User" lazy="false" table="Users"> <id name="Id" type="int"> <generator class="native"/> </id> <property name="Name" /> <bag name="RoleList" table="User_Role" inverse="true" lazy="false" collection-type="Roles"> <key column="UserId" foreign-key="Id"/> <many-to-many class="Role" column="RoleId"/> </bag> </class> I am tracking all the queries to the SQL server. When I select user, I also see the SQL SELECT statement (which is Ok). The problem is when 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

NHibernate Error Message: Invalid index 3 for this SqlParameterCollection with Count=3

有些话、适合烂在心里 提交于 2019-12-21 10:57:54
问题 I have a test database design like this: The following is the pseudo-code: //BhillHeader public class BillHeader { public BillHeader() { BillDetails = new List<BillDetail>(); } public virtual int BillNo { get; set; } public virtual IList<BillDetail> BillDetails { get; set; } public virtual decimal Amount { get; set; } public virtual void AddDetail(BillDetail billdet) { BillDetails.Add(billdet); } } //BillHeader Map public class BillHeaderMap : ClassMap<BillHeader> { public BillHeaderMap() {

Is it possible to call a stored procedure using NHibernate which returns a custom object instead of domain object?

蓝咒 提交于 2019-12-21 06:35:46
问题 I have several stored procedures that don't return the domain objects (i.e; objects which have corresponding sql table mapping in hbm files); but return the custom objects instead. I want to call these stored procedures using NHibernate and fill my custom objects with the output automatically, instead of filling them mannually as I would do if I use a SqlDataReader. An example shall be highly appreciated. BTW: I use nhibernate 3.2 new feature mapping by code. 回答1: Maybe you can try the

Is it possible to call a stored procedure using NHibernate which returns a custom object instead of domain object?

北战南征 提交于 2019-12-21 06:33:30
问题 I have several stored procedures that don't return the domain objects (i.e; objects which have corresponding sql table mapping in hbm files); but return the custom objects instead. I want to call these stored procedures using NHibernate and fill my custom objects with the output automatically, instead of filling them mannually as I would do if I use a SqlDataReader. An example shall be highly appreciated. BTW: I use nhibernate 3.2 new feature mapping by code. 回答1: Maybe you can try the