nhibernate

NHibernate: How to increment a column value without concurrency issues

与世无争的帅哥 提交于 2020-01-05 06:44:25
问题 I have a database table CaseSymbol with columns: id , Symbol , LastNo It runs over ASP.NET MVC application. Multiple application instances can get the symbol and increment LastNo . CaseSymbol symbol = this.context.CurrentSession.Get<CaseSymbol>(id); symbol.LastNo++; Then it crashes obviously on following line: this.context.CurrentSession.Flush(); with following exception NHibernate.StaleObjectStateException: 'Row was updated or deleted by another transaction I tried to wrap it in transaction

nhibernate generate mapping files from existing database

旧巷老猫 提交于 2020-01-05 06:42:26
问题 I'm working with NHibernate. We have a huge existing Database (more than 1.000 tables). I want to map all those tables with NHibernate (with hbm.xml and cs files). I tried to do the job with the NHibernate Mapping Generator, unfortunately the generated files are not able to compile. Too many little errors caused by multiple Foreign Keys related to same Table or Case Sensitivity (wrong namespace ,...) and so on. So my question...is there a tool outside which is still supported and has a huge

Map Entities to self-joined Table by Id

≯℡__Kan透↙ 提交于 2020-01-05 05:48:04
问题 My legacy table "AllData" has those columns: Id, Title, LookupColumn1Id My entities: public class BaseEntity { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class Employee: BaseEntity { public virtual int DepartmentId { get; set; } public virtual string DepartmentName { get; set; } } public class Department: BaseEntity { public virtual int HeadManagerId { get; set; } } I want to generate SELECT like this: SELECT EmployeeTable.Title, DepartmentTable.Id,

Nhibernate migrate ICriteria to QueryOver

时光毁灭记忆、已成空白 提交于 2020-01-05 05:41:47
问题 We are using ICriteria and now we would like to switch to more readable QueryOver in Nhibernate Can someone give me a hint how to convert this generic pagination logic for Icriteria to QueryOver? public static PagedList<T> PagedList<T>(this ICriteria criteria, ISession session, int pageIndex, int pageSize) where T : class { if (pageIndex < 0) pageIndex = 0; var countCrit = (ICriteria)criteria.Clone(); countCrit.ClearOrders(); // so we don’t have missing group by exceptions var results =

Can I use NHibernate SysCache with Non-Web-Application?

风流意气都作罢 提交于 2020-01-05 04:39:07
问题 I have a Windows Service which is using NHibernate (3) and SQL Server 2008. WPF-Clients are connecting over WCF to this Service for using DataAccess. My question is now: Can I use SysCache or SysCache2 in this Scenario - or are they only usable in Web-/ASP.NET-Applications? 回答1: Yes, it works just fine. You can use it even in a console app if you want to (provided the computer has the full .NET Framework installed and not just the Client Profile). 来源: https://stackoverflow.com/questions

AutoMapping a Composite Element in Fluent Nhibernate

坚强是说给别人听的谎言 提交于 2020-01-05 04:38:07
问题 I'm trying to get the AutoPersistence model to map several composite elements. However, it seems that either I end up mapping it as an entity, dropping down to manual mapping or it just doesn't plain work. Here's some code that demonstrates my problem: using System; using System.Collections.Generic; using FluentNHibernate.AutoMap; using FluentNHibernate.Cfg; using FluentNHibernate.Conventions.Helpers; using NHibernate.Cfg; namespace Scanner { public class Root { public int Id { get; set; }

Stack Overflow whilst cascade saving nhibernate entity with custom generator

瘦欲@ 提交于 2020-01-05 04:18:16
问题 I'm pretty new to Nhibernate, so apologies for a long - winded description I suspect that changing the structure of the legacy DB is probably the best option, but I want to try and get NHibernate to deal with it. Basically the structure is this an EndPoint has an address and a contact. Endpoint is stored in a table with a composite ID (Address ID, Contact ID). I'm having a problem when cascade saving an address, which has a custom ID generator - address ID are of the form "ADR000234" to fit

NHibernate w/ database mirroring via Failover Partner in connection string

时光怂恿深爱的人放手 提交于 2020-01-05 03:47:09
问题 I'll preface this question by saying I am using NHibernate v3.2 . Let's say I have a connection string like the following (the key here is the Failover Partner ): Data Source=Server1\Instance;Failover Partner=Server2\Instance;Initial Catalog=MyDb;Integrated Security=True; I found the following article related to this topic in a hibernate forum: https://forum.hibernate.org/viewtopic.php?f=25&t=979764 One user mentions the following: We had a slight hiccup with the way we were caching our

Fluent NHibernate: How to create circular one-to-one mapping?

╄→гoц情女王★ 提交于 2020-01-05 03:33:45
问题 public class AdminUser { public virtual int Id { get; set; } public virtual string UserName { get; set; } public virtual string Password { get; set; } public virtual bool IsLocked { get; set; } public virtual AdminUser Creator { get; set; } public virtual DateTime CreationDate { get; set; } } public class AdminUserMapping : ClassMap<AdminUser> { public AdminUserMapping() { Id(c => c.Id).GeneratedBy.Native(); Map(c => c.UserName).Not.Nullable(); Map(c => c.Password).Not.Nullable(); Map(c => c

How to call a procedure using NHibernate that returns result from multiple tables?

人走茶凉 提交于 2020-01-05 02:29:35
问题 Normally we create 1:1 mapping per table-class. Ex(Tables): [users] user_id - PK name [transactions] user_id - FK item_id amount Example mapping: public class User { public string ID {get; set;} public string Name {get; set;} } public class Transaction { public string UserID {get; set;} public string ItemID {get; set;} public Decimal Amount {get; set;} } But due to optimization concern and sometimes there are operations needed to be done while querying for results; we usually use stored