nhibernate

How can I generate NHibernate mapping files and DB constructs from my domain logic?

人走茶凉 提交于 2020-01-04 05:54:46
问题 I want to implement NHibernate on my domain objects in my project, but I'm not sure how I should go about generating the mapping file, and the database. I've found some questions that kind of touch on this here and here, but I'm starting with my classes already defined, and would like to start from them and work my way down, not the other way around. Is there any way to do this? I'm perfectly fine with a multi-stage process, I just want to know what other people have done that was successful

NHibernate QueryOver With Paging While Selecting Top 1 Of SubQuery

╄→尐↘猪︶ㄣ 提交于 2020-01-04 05:25:07
问题 I have 2 entities (These are broken down to question to be simpler): Entity A public class EntityA { protected IList<EntityB> _bList = new List<EntityB>(); virtual public int Id { get; set; } virtual public int ExtId { get; set; } public virtual void AddB(EntityB b) { if (!_bList.Contains(b)) _bList.Add(b); b.A = this; b.ExtId = this.ExtId; } public virtual void RemoveB(EntityB b) { _bList.Remove(b); } public virtual IList<EntityB> BList { get { return _bList.ToList().AsReadOnly(); } } }

Want to save selected (i.e., more than 1) enums as string with NHibernate

强颜欢笑 提交于 2020-01-04 05:17:46
问题 I cannot for the life of me get this to work with my existing code, but I am trying to save my enum selections as strings in NHibernate. Basically, I have a UI check box and if the user selects multiple check boxes I want to store those selections. Now, I can get NHibernate to store ONE selection (e.g., from a drop down or radio button list, where the user is limited to one choice only). This is the jist of what I have for an enum: public enum IncomeType { [Display(Name = "Full-Time

Want to save selected (i.e., more than 1) enums as string with NHibernate

笑着哭i 提交于 2020-01-04 05:17:29
问题 I cannot for the life of me get this to work with my existing code, but I am trying to save my enum selections as strings in NHibernate. Basically, I have a UI check box and if the user selects multiple check boxes I want to store those selections. Now, I can get NHibernate to store ONE selection (e.g., from a drop down or radio button list, where the user is limited to one choice only). This is the jist of what I have for an enum: public enum IncomeType { [Display(Name = "Full-Time

How to have NHibernate persist a String.Empty property value as NULL

℡╲_俬逩灬. 提交于 2020-01-04 05:16:19
问题 I have a fairly simple class that I want to save to SQL Server via NHibernate (w/ Fluent mappings). The class is made up mostly of optional string fields. My problem is I default the class fields to string.empty to avoid NullRefExceptions and when NHibernate saves the row to the database each column contains an empty string instead of null. Question: Is there a way for me to get NHibernate to automatically save null when the string property is an empty string? Or do I need to litter my code

NHibernate Lazy Loading Behaviour

走远了吗. 提交于 2020-01-04 05:12:19
问题 I was reading this article on Nhibernate Lazy Loading http://nhforge.org/wikis/howtonh/lazy-loading-eager-loading.aspx and it uses and example of a class structure like this: The article then shows the following code: using (ISession session = SessionFactory.OpenSession()) { var fromDb = session.Get<Order>(_order.Id); int sum = 0; foreach (var line in fromDb.OrderLines) { // just some dummy code to force loading of order line sum += line.Amount; } } It then goes on to talk about: the n+1

Deep copy entity with NHibernate

雨燕双飞 提交于 2020-01-04 05:09:52
问题 I am currently starting a new ASP.NET MVC Project at work where we need to generate a project cost estimate. We are using NHibernate, ASP.NET MVC 1.0 and StructureMap. The client wants to be able to fill all the information about the project, the information is in different pages and we need to persist in between each post back. The client does not want to have the option to Save it under a name when it is completed, but we want to persist it in the database even when he did not save it yet.

NHibernate: cannot resolve inherited id property

混江龙づ霸主 提交于 2020-01-04 04:53:08
问题 I have the entity defined below: public class Foo : Entity<Foo.FooId> { public class FooId { public virtual String Bar { get; protected internal set; } public virtual Int32 Buzz { get; protected internal set; } } // ... } And here's the base class: public abstract class Entity<T> : IEquatable<Entity<T>> { public virtual T Id { get; protected internal set; } // ... } I'm going to map the "Id" property as a "composite key", so I've added the following mapping class: public class FooMap :

Fluent NHibernate: How to tell it not to map a base class

自闭症网瘾萝莉.ら 提交于 2020-01-04 04:26:28
问题 I have been googling and stackoverflowing for the last two hours and couldn't find an answer for my question: I'm using ASP.NET MVC and NHibernate and all I'm trying to do is to manually map my entities without mapping its base class. I'm using the following convention: public class Car : EntityBase { public virtual User User { get; set; } public virtual string PlateNumber { get; set; } public virtual string Make { get; set; } public virtual string Model { get; set; } public virtual int Year

Issues with NHibernate QueryOver and Subqueries

陌路散爱 提交于 2020-01-04 04:18:22
问题 I have the following model: public class User { public virtual int Id { get; set; } public virtual string Username { get; set; } public virtual string Password { get; set; } public virtual string Email { get; set; } public IList<SubmissionNote> Notes { get;set; } } public class SubmissionNote { public virtual Int64 Id { get; set; } public virtual string Text { get; set; } public virtual DateTime CreatedOn { get; set; } public virtual User Creator { get; set; } public virtual Submission