nhibernate

Ignore column using mapping by code in HNibernate

混江龙づ霸主 提交于 2019-12-24 10:48:55
问题 I'm using mapping by code in NHibernate. I got a class with several properties. One of them is not related to any columns in DB but still has getter and setter. I use ConventionModelMapper not ModelMapper. The first one assumes that all properties are mapped. How i can tell to NHibernate to ignore it? 回答1: Why not map the properties you want and leave the ones not needed to be mapped check this You can manage the persistence of ConventionModelMapper as following: mapper.BeforeMapProperty +=

fluent nHibernate: How to persist a property which is mapped with Formula?

自闭症网瘾萝莉.ら 提交于 2019-12-24 10:31:06
问题 I am dealing with a legacy database, and we have a field which doesn't make sense anymore, but I would rather not change the DB schema. I'm trying to map an old DB text field into a class with a boolean (only need to know about one option that the DB text field has). I can get the boolean value out of the DB using Forumla, but I can seem to get it to save any updates back into the DB. My class and current fluent mapping for it is: public class Bulletin { public virtual int Id { get; set;}

How connect nhibernate to local SQLEXPRESS?

我只是一个虾纸丫 提交于 2019-12-24 10:27:16
问题 I have in project simple connection to database: public static string GetConnectionString() { return @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + HttpContext.Current.Request.PhysicalApplicationPath + "Application.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; } Now I try to implement NHibernate to project. hibernate.cfg.xml here: <?xml version="1.0" encoding="utf-8"?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name=

NHibernate: Criteria query slow in web app but fast in unit tests, why?

旧街凉风 提交于 2019-12-24 09:59:22
问题 I am having a problem where a criteria query in NHibernate is executes in less then a second when I run it in a unit test, but when I try to run it from the context of my web application, it takes over a minute. Both are hitting the same database for the same data. My NHibernate mapping: var properties = new Dictionary<string, string>(); var configuration = new Configuration(); properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider"); properties.Add(

NHibernate correlated subquery fetching single item

丶灬走出姿态 提交于 2019-12-24 09:35:59
问题 I'm using NHibernate 3.2 and have the following model: class User { public virtual int Id { get; set; } public virtual string Username { get; set; } public virtual IList<Log> Logs { get; set; } } class Log { public virtual int Id { get; set; } public virtual User User { get; set; } public virtual DateTime Date { get; set; } } Now, I want to query User with the date of ther latest Log-entry. class UserDto { public int UserId { get; set; } public string Username { get; set; } public DateTime?

NHibernate QueryOver - collection with too many results

六月ゝ 毕业季﹏ 提交于 2019-12-24 09:29:12
问题 Dear NHibernate users, I've been trying, reading and whatnot for 2 days now, but still can't figure this out, even though I presumed it to be an easy task with QueryOver API. These are my two entities: ATTRIBUTE --------------------------- public int Id { get; set; } public int LanguageId { get; set; } public string Title { get; set; } public IList<Option> Options { get; set; } OPTION --------------------------- public int Id { get; set; } public Attribute Attribute { get; set; } public int

Hibernate performance issue with OneToMany / nullable relationship

99封情书 提交于 2019-12-24 09:16:50
问题 We use @OneToMany for our Parent->Child->Child->Child DB relationship: @OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "THE_ID", nullable = false ) private List<ChildClass> children = new ArrayList<ChildClass>(); We have a scenario with a lot of data (100K inserts) where the performance is atrocious (actually times out) when inserting. With a small amount of data (1K inserts) we are however fine. So for no good reason I have removed the nullable = false and changed the DB foreign key

How to get an object from the database with NHibernate?

末鹿安然 提交于 2019-12-24 09:14:03
问题 I'm trying to get an object back from an NHibernate query. My method is as follows: public Site GetSiteByHost(string host) { var result = _session.CreateCriteria<Site>() .Add(SqlExpression.Like<Site>(g => g.URLName, host)); return result; } the problem is, result is a type of HNibernate.ICriteria. How can I get this to return a Site object? If I was doing this with LINQ to SQL it'd be something like .FirstOrDefault() but that's not available with NHibernate... or is it?!?! 回答1: You need to

How to create dynamic NHibernate mappings without generating HBM XML files?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 09:06:55
问题 I'm working on a dynamic application with NHibernate. My goal is to create dynamic entities (both class type and mapping xml file) based on some data. For example suppose I want to create a Person entity dynamically in runtime and on the fly. I use Reflection.Emit to generate class type dynamically. For creating mapping dynamically I used Ayende's code.. But unfortunately this code does not work because mappings does not have Classes property. I tried to code as same as codes of Castle

Using DI to add Interceptor to NHibernate Sessions in legacy code

若如初见. 提交于 2019-12-24 08:51:10
问题 So, there's a bug in some legacy code I'm maintaining. It causes some mild data corruption, so it's rather serious. I've found the root cause, and have made a sample application that reliable reproduces the bug. I would like to fix it with as little impact on existing applications as possible, but I'm struggling. The bug lies in the data access layer. More specifically, in how an interceptor is injected into a new Nhibernate Session. The interceptor is used to set a specific entity property