nhibernate

Where to configure NLog NHibernate bridge for logging sql configuration?

穿精又带淫゛_ 提交于 2019-12-24 03:58:08
问题 As a proof-of-concept I am using a console application wrapping a proxy of a WCF service. I execute a few calls through the proxy and write the results to the console. Underlying the WCF service is a Data Access Layer built on the Repository pattern using NHibernate as an ORM. I want to write the NHib-generated SQL to the console. I have attempted to configure NLog using the NuGet package and guidance from here with no luck, but I suspect perhaps I don't properly understand where I need to

Setting clustered index in nhibernate

蹲街弑〆低调 提交于 2019-12-24 03:56:10
问题 I'm trying to define a property that is not the id as a clustered index in nhibernate, yet I've found no way of doing this. Could anyone give me a pointer of how this is done, or it is something not currently available in nhibernate? Thanks in advance 回答1: You can use <database-object> to create indexes and other artifacts. http://nhibernate.info/doc/nhibernate-reference/mapping.html#mapping-database-object 来源: https://stackoverflow.com/questions/3070355/setting-clustered-index-in-nhibernate

Fluent NHibernate table-per-class-hierarchy need to use .Where()?

江枫思渺然 提交于 2019-12-24 03:53:28
问题 I have the following mapping for a set of contact classes based off an abstract Contact class implementation. public class ContactMapping : ClassMap<Contact> { public ContactMapping() { Id(x => x.Id).GeneratedBy.GuidComb(); Map(x => x.CreatedDate).Not.Nullable(); Map(x => x.Value).Not.Nullable(); Map(x => x.Level).Not.Nullable(); Map(x => x.Comments); DiscriminateSubClassesOnColumn("ContactType"); } } public class PhoneContactMapping : SubclassMap<PhoneContact> { public PhoneContactMapping()

Modify SQL in NHibernate

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 03:52:30
问题 I need to know how to modify a sql, to add to every select a sql code. My problem is, I need to add this sql code after a "FROM table" + " sql_code", even if there is something after "like a GROUP BY". I know that I need to use the OnPrepareStatement, I just don't know how to edit the SqlString to do so ! One thing that I've tried: public override SqlString OnPrepareStatement(SqlString sql) { if (sql.Parts.Cast<string>().FirstOrDefault().Trim().ToLower() != "select") { return sql; }

Modify SQL in NHibernate

落爺英雄遲暮 提交于 2019-12-24 03:52:29
问题 I need to know how to modify a sql, to add to every select a sql code. My problem is, I need to add this sql code after a "FROM table" + " sql_code", even if there is something after "like a GROUP BY". I know that I need to use the OnPrepareStatement, I just don't know how to edit the SqlString to do so ! One thing that I've tried: public override SqlString OnPrepareStatement(SqlString sql) { if (sql.Parts.Cast<string>().FirstOrDefault().Trim().ToLower() != "select") { return sql; }

How to configure custom MySQL NHibernate Batcher?

别说谁变了你拦得住时间么 提交于 2019-12-24 03:38:11
问题 NHibernate with MySQL Dialect does not support Batching out of the box. I have found custom MySQL Batcher for NHibernate on nuget. Also, following is the github link: https://github.com/Andorbal/NHibernate.MySQLBatcher But I do not know how to inject/set this into my hibernate.cfg.xml configuration. How to configure custom MySQL NHibernate Batcher? 回答1: The property you need to set is call "adonet.factory_class". Use any of the following: <property name="adonet.factory_class">assembly

Selection in GroupBy query with NHibernate with dynamic anonymous object

…衆ロ難τιáo~ 提交于 2019-12-24 03:38:08
问题 My main objective is to create a dynamic group by and use it in NHibernate. Consider this non dynamic example that works : _repository.Collection<User>().GroupBy(u => new { u.Active }).Select(s => s.Key, Count = s.Count()) Now, I create a dynamic object to generate the new { u.Active } part dynamically: private Expression<Func<T, object>> CreateGrouping<T>(IEnumerable<string> by) { var dynamicTypeForGroup = GetDynamicTypeForGroup<T>(by); var sourceItem = Expression.Parameter(typeof(T)); var

(Fluent) NHibernate mapping for class with calculated properties

╄→尐↘猪︶ㄣ 提交于 2019-12-24 03:28:09
问题 I have the a class similar to the following (nb! names have been changed to protect the innocent): public class Person { public virtual int Id { get; private set; } public virtual string Name { get; set; } public virtual DateTime Birthday { get; set; } public virtual TimeSpan Age { get { return DateTime.Now - this.Birthday; } } } I use Fluent NHibernate to configure my mapping: public class PersonMap : ClassMap<Person> { public PersonMap() { Id(x => x.Id); Map(x => x.Name); Map(x => x

Querying via NHibernate without an N+1 - sample included

谁都会走 提交于 2019-12-24 03:22:29
问题 I have an N+1 problem and I'm not sure how to solve it. A fully-reproducible sample may be found at the bottom of this question. So if you are willing, please create the database, set up the NUnit test and all the accompanying classes, and try to eliminate the N+1 locally. This is the anonymized version of a real problem I encountered. For all you know, this code is crucial in helping launch the next space shuttle to the moon. I won't deny it if asked. To summarize the problem: I am trying to

NHibernate Session.SetReadOnly

大城市里の小女人 提交于 2019-12-24 03:16:49
问题 I'm facing the same issue others already posted on SO: On reading objects from the database, NHibernate would update all the objects because the value of one field is not proper in the DB. (In detail: A newly added date column contains "1/1/0001" in all rows, so on mapping, NHibernate replaces the date and, on tx.Commit(), updates every single row.) [ Edit: It turned out that this was wrong. Instead, these date fields were null but would be updated to 1/1/0001 by NHibernate. See Diego's