nhibernate

NHibernate insert generates updates for collection items

给你一囗甜甜゛ 提交于 2020-01-16 17:36:58
问题 How should I configure my mappings to avoid NHibernate updating my child entities' foreign keys right after inserting them? E.g. Parent class is mapped like this: class ParentMap : ClassMap<Parent> { public ParentMap() { Id(x => x.Id) .GeneratedBy.Increment(); Map(x => x.Name); HasMany(x => x.ChildNodes) .KeyColumns.Add("Parent_id") .Cascade.All(); } } Let Parent have a bunch of Child objects: Parent p = new Parent("test"); p.ChildNodes.AddRange(GetSomeDummyNodes()); When I save the parent

Many-to-one relation exception due to closed session after loading

妖精的绣舞 提交于 2020-01-16 17:36:28
问题 I am using NHibernate (version 1.2.1) for the first time so I wrote a simple test application (an ASP.NET project) that uses it. In my database I have two tables: Persons and Categories. Each person gets one category, seems easy enough. | Persons | | Categories | |--------------| |--------------| | Id (PK) | | Id (PK) | | Firstname | | CategoryName | | Lastname | | CreatedTime | | CategoryId | | UpdatedTime | | CreatedTime | | Deleted | | UpdatedTime | | Deleted | The Id, CreatedTime,

Parameterized SQL - in / not in with fixed numbers of parameters, for query plan cache optimization?

血红的双手。 提交于 2020-01-16 14:30:44
问题 If SQL is used directly or created by NHibernate, with possibly big "where in / not in ([1 to 100 parameters])" conditions, does it make sense to fill up parameters to certain limits, to have a limited number of query plans? Parameters are int/number, DBMS is MSSQL or Oracle. The queries are called via sp_executesql/executeimmediate to enforce query plan caching. Normally, such a query would have up to 100 query plans for the same query. Several such queries might quickly fill up the cache,

NHibernate DateTime for query, Overflow exception caused by string format

半城伤御伤魂 提交于 2020-01-16 08:50:11
问题 NHibernate is generating the following SQL which is not supported by Firebird; where (struct_cas0_.DELETED IS NULL) and struct_cas0_.ACCOUNT_ID = 372 /* @p0 */ and struct_cas0_.DATE_RECORD <= '2005-01-01T00:00:00.00' /* @p1 */ and struct_cas0_.DATE_RECORD >= '2006-12-31T00:00:00.00' /* @p2 */ The above SQL fails in firebird with an error "Overflow occurred during data type conversion. Conversion error from string '2005-01-01T00:00:00.00'" If we remove the 'T' from the query, Firebird executes

Setting CustomSqlType on References

一个人想着一个人 提交于 2020-01-16 06:12:49
问题 I have a situation where my primary key is a char(2) in SqlServer 2008, and I want to reference it in a one-to-many relationship, but the ManyToOneBuilder (which is returned by ClassMap<>.References()) doesn't have a CustomSqlType() method. Specifically: public class State { // state FIPS code is 2 characters public virtual string StateCode { get; set; } public virtual ICollection<County> { get; set; } } public class County { // state-county FIPS code is 5 characters public virtual string

Castle Facilities NHibernateIntegration for NHibernate 4.0

痞子三分冷 提交于 2020-01-16 00:50:26
问题 I downloaded the source for NHibernateIntegration from (https://github.com/mahara/Castle.Facilities.NHibernateIntegration) I added reference for Castle.Core (3.3.0.0), Castle.Services.Transaction (3.3.0.0), Castle.Windsor (3.3.0.0), NHibernate (4.0.0.4000) and I built the application to generate the Castle.Facilities.NHibernateIntegration.dll But after the upgrading NHibernateIntegration.dll in my application I am getting the following error, An ISessionFactory component was not mapped for

NHibernate Fluently Configure Default Flush Mode for Session / SessionFactory

≡放荡痞女 提交于 2020-01-15 23:02:44
问题 I am using FluentNHibernate and trying to configure Environment.DefaultFlushMode to FlushMode.Commit According to this SO question it should be possible: How to change default FlushMode to Commit in C#? Indeed, this feature was added https://nhibernate.jira.com/browse/NH-3619 Here is how I use it: public ISessionFactory BootstrapSessionFactory() { return Fluently.Configure() .ExposeConfiguration(cfg => cfg.SetProperty(Environment.DefaultFlushMode, FlushMode.Commit.ToString()))

Call a Stored Procedure with a DetachedCriteria?

不问归期 提交于 2020-01-15 12:44:27
问题 Is it possible to construct a DetachedCriteria in nHibernate which queries a stored procedure? How would I accomplish such a task? 回答1: I have not done it but you can use some alternatives: Named Queries and SQL Queries Map to a view instead. Map to a TableValued Function (yes this I know this isn't great but it's got me out of a few jams) 回答2: No, it's not possible. You have to use a SQLQuery to call a stored procedure. 来源: https://stackoverflow.com/questions/6611124/call-a-stored-procedure

Call a Stored Procedure with a DetachedCriteria?

感情迁移 提交于 2020-01-15 12:43:20
问题 Is it possible to construct a DetachedCriteria in nHibernate which queries a stored procedure? How would I accomplish such a task? 回答1: I have not done it but you can use some alternatives: Named Queries and SQL Queries Map to a view instead. Map to a TableValued Function (yes this I know this isn't great but it's got me out of a few jams) 回答2: No, it's not possible. You have to use a SQLQuery to call a stored procedure. 来源: https://stackoverflow.com/questions/6611124/call-a-stored-procedure

NHibernate always hydrates many-to-one

巧了我就是萌 提交于 2020-01-15 12:35:07
问题 I am experiencing something weird when using NHibernate. I have opened up a codebase that I didn't write, and the one who did isn't here anymore. So I guess what I am looking for is more tips on debugging than anything else. I am using NHIbernate 3.4 Linq provider, to query an entity, that has a many-to-one relationship to another entity. What I see is the even though I never access the property that represents the many-to-one relation it is always hydrated. From looking at the queries