nhibernate

How can I use TransactionScope with SQL Compact 4.0 and NHibernate

血红的双手。 提交于 2019-12-24 00:07:09
问题 I am trying to use NHibernate in combination with .NET's TransactionScope object. So far I have successfully used Oracle 11g and SQL Server 2008R2 with no issues. However, SQL Compact seems to fall on its face. using (var scope = new TransactionScope(TranactionScopeOption.Required)) { using (var session = _sessionFactory.OpenSession()) { // The line below throws. I also tried passing in System.Data.IsolationLevel.ReadCommitted to no avail using (var txn = session.BeginTransaction()) { //

What are the problems associated with sending a Hibernate Proxy class to clients

心不动则不痛 提交于 2019-12-23 23:12:53
问题 I have a POCO classes that I am using with NHibernate in a WCF service layer. And I am thinking about trying to send the NHibernate proxy classes down to a client. This is a client that I control. We handle record updates with a system wide reservation so there can only be one writable copy of this entity sent to a client at any given time. My basic goal is to take advantage of NHibernates change tracking so I don't need to fetch a copy from the database and replay the changes the client made

How do I get NHibernate to save an entity if I assign it an ID, but generate one otherwise?

半城伤御伤魂 提交于 2019-12-23 23:09:04
问题 According to the REST philosophy, a PUT request should update the resource at a URL if it exists, and create it if it doesn't exist. So in other words, if I use the following URL: PUT http://server/item/5 If an Item exists with an ID of 5, it will be updated. If an Item doesn't exist with an ID of 5, a new Item will be created with an ID of 5. However, I'm using NHibernate for persistence, and I mapped my IDs as Identity . This means that no matter what value I assign the ID, NHibernate will

C#/NHibernate - Get first 10 records ordered by grouped sum

拟墨画扇 提交于 2019-12-23 22:58:04
问题 Well, basically I'm trying to figure out a way to get the 10 most sold products. Something I could easily achieve with the following SQL Query: SELECT `product`.* FROM `product` INNER JOIN `sale_item` ON `product`.`id` = `sale_item`.`product_id` GROUP BY `product`.`id` ORDER BY SUM(`sale_item`.`quantity`) DESC LIMIT 10; The closest I got to succeeding with NHibernate, I believe was this: ICriteria criteria = NHibernateSession .CreateCriteria<SaleItem>("SaleItem") .SetMaxResults(10)

nhibernate: how to setup entity validation that uses data from database?

↘锁芯ラ 提交于 2019-12-23 22:27:03
问题 I've setup nhibernate but I have problems with validating entity before the actual save and commit to database. As I load and change persistent entity, validation that goes after is accessing the database and by doing so commiting the transaction, thus saving entity in database before the actual validation result is known. I use Repository pattern in .NET MVC web app and it goes like this: public ActionResult Edit(int id, Entity entity) { var repository = new EntityRepository(); // get

NHibernate COALESCE issue

久未见 提交于 2019-12-23 21:29:00
问题 I am trying to express the following SQL query with NHibernate DECLARE @date DATETIME = NULL; SELECT ER.Id , ER.DocumentDate FROM ExpenseReport ER WHERE ER.PeriodFrom >= COALESCE(@date, ER.PeriodFrom) OR ER.PeriodTo <= COALESCE(@date, ER.PeriodTo); So, in the C# part I do have the following classes: for the entity : ExpenseReport for my search itself a separate class Code snippets: // ----- Entity class. public partial class ExpenseReport { public Nullable<System.DateTime> PeriodFrom { get;

FluentNHibernate Component.ColumnPrefix not being applied

拈花ヽ惹草 提交于 2019-12-23 20:24:02
问题 I recently upgraded FluentNHibernate from v1.1.0.685 to v1.2.0.712 (latest) for NHibernate 2.1 . My issue appears to be with classes that use the Component().ColumnPrefix() mapping. For example, public class Address{ public string Street {get; set;} public string Zip {get; set;} } public class AddressMap : ComponentMap<Address>{ Map( x => x.Street ); Map( x => x.Zip ); } public class PersonMap : ClassMap<Person> { public PersonMap(){ Id( x => x.Id ); Map( x=> x.Name ); Component( x => x

nhibernate dynamically bind a class

我的梦境 提交于 2019-12-23 20:15:03
问题 I've read this article, and am looking for a way to dynamically change my mapping at runtime to bind to a different table using a one-to-many dependent on a value in my parent object. Here are my mappings <bag name="Data" mutable="true" > <key> <column name="Log_Link" /> <column name="channel" /> </key> <one-to-many class="Fluent.Entities.Meters.FTIMeterChannelData, Poco" entity-name="30" /> </bag> and <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import

Indexed views & Nhibernate - NOEXPAND Hint?

烂漫一生 提交于 2019-12-23 19:57:22
问题 Is it possible to configure NHibernate to issue the NOEXPAND hint when it executes a select statement against an indexed view? SQL Server always skips the views and goes straight to the base tables when executing queries unless the hint is used. 回答1: Here is a hack I tried and it worked. Just added (NOEXPAND) to the "table" name. <class name="ClassName" mutable="false" table="vw_ViewName (NOEXPAND)"> ... </class> 来源: https://stackoverflow.com/questions/6269549/indexed-views-nhibernate

Should i use nhibernate for a fairly small project?

隐身守侯 提交于 2019-12-23 19:24:07
问题 Let me say i know NOTHING about nhibernate except its for databases. I am doing a fairly small project, should i learn nhibernate? I guess i have 4 questions Is using a nhibernate overkill in a small project? What should i NOT use nhibernate for? if i have a large project should i use nhibernate if it has very complex tables? What about simple table schemes? 回答1: nhibernate is a very flexible system and can be used with simple databases or more complex ones. The real question comes down to