fluent-nhibernate

Fluent nhibernate: How do I map an entity with a property who's type is an interface?

流过昼夜 提交于 2019-12-03 17:08:32
I have an entity like: public class Employee { public int ID { get; set; } public IAccountManager AccountManager { get; set; } ... } I also have a mapping defined for "DefaultAccountManager" - a concrete implementation of IAccountManager. When mapping the above "Employee" entity, how do I tell NHibernate to persist/load the AccountManager property using the mapping defined in "DefaultAccountManager"? Edit: Actually if I could setup a mapping for IAccountManager so that NHibernate could just infer which implementer to load/persist that would be even better. I'd rather not have to break

Fluent Nibernate putting a where clause in the mapping

爱⌒轻易说出口 提交于 2019-12-03 16:39:55
I've got two objects a parent and a child list. In my fluent nhibernate mapping for the parent I want to load the list of the children. However I want this to be conditional, a column in the child table is called "IsDeleted" and I only want to return the children where "IsDeleted" is false. Is it possible to set up a mapping to do this? If not is it possible to do it in just standard nhibernate? Thanks Yes, you can use a Where constraint in Fluent NHibernate to map this. Somehting like: HasMany(x => x.Children).Where("IsDeleted = 0"); The Where constraint should use SQL syntax not HQL. For

How do I handle table relationships with the repository pattern?

◇◆丶佛笑我妖孽 提交于 2019-12-03 16:34:08
问题 I'm implementing the repository pattern as part of an ASP.NET MVC site. Most examples I've seen of repositories are fairly simple. For example here's a typical abstract repository interface. public interface IRepository<TEntity> { IQueryable<TEntity> All(); TEntity FindBy(int id); TEntity FindBy(Expression<Func<TEntity, bool>> expression); IQueryable<TEntity> FilterBy(Expression<Func<TEntity, bool>> expression); bool Add(TEntity entity); bool Update(TEntity entity); bool Delete(TEntity entity

How to store a non truncated varchar(max) string with NHibernate and Fluent NHibernate

风格不统一 提交于 2019-12-03 16:30:13
问题 My DB schema has a string as a varchar(max). I have read the other questions concerning setting Length to more than 4000 or 8000 so that it really generates a (n)varchar(max) in the mapping but when I use Length(10000) in my mapping class, the hbm file actually shows length="10000" and if I save an entity with more than 10000 chars, it is actually truncated to exactly 10000 chars. I don't want any truncation. (using NH3-alpha2 and FNH trunk) 回答1: It would appear that this is an old problem

Problem with Nhibernate.Bytecode.Castle in MSBuild (TFS)

ぃ、小莉子 提交于 2019-12-03 16:15:29
We have a Fluent NHibernate mapping test that is passing on our local machines, but when we check in to TFS, the tests are failing on the build server. We are using MSTest. The error we get is: NHibernate.Bytecode.UnableToLoadProxyFactoryFactoryException: Unable to load type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class. Possible causes are: - The NHibernate.Bytecode provider assembly was not deployed. - The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well

Fluent NHibernate one-to-many relationship setting foreign key to null

自古美人都是妖i 提交于 2019-12-03 15:52:35
I have a simple Fluent NHibernate model with two related classes: public class Applicant { public Applicant() { Tags = new List<Tag>(); } public virtual int Id { get; set; } //other fields removed for sake of example public virtual IList<Tag> Tags { get; protected set; } public virtual void AddTag(Tag tag) { tag.Applicant = this; Tags.Add(tag); } } public class Tag { public virtual int Id { get; protected set; } public virtual string TagName { get; set; } public virtual Applicant Applicant { get; set; } } My fluent mapping is the following: public class ApplicantMap : ClassMap<Applicant> {

Fluent Nhibernate left join

五迷三道 提交于 2019-12-03 15:30:23
问题 I want to map a class that result in a left outer join and not in an innner join. My composite user entity is made by one table ("aspnet_users") and an some optional properties in a second table (like FullName in "users"). public class UserMap : ClassMap<User> { public UserMap() { Table("aspnet_Users"); Id(x => x.Id, "UserId").GeneratedBy.Guid(); Map(x => x.UserName, "UserName"); Map(x => x.LoweredUserName, "LoweredUserName"); Join("Users",mm=> { mm.Map(xx => xx.FullName); }); } } this

NHibernate -failed to lazily initialize a collection of role

空扰寡人 提交于 2019-12-03 15:04:16
问题 I have the following seemingly simple scenario, however I'm still pretty new to NHibernate. When trying to load the following model for an Edit action on my Controller: Controller's Edit Action: public ActionResult Edit(Guid id) { return View(_repository.GetById(id)); } Repository: public SomeModel GetById(Guid id) { using (ISession session = NHibernateSessionManager.Instance.GetSession()) return session.Get<SomeModel >(id); } Model: public class SomeModel { public virtual string Content {

NHibernate dynamic mapping

家住魔仙堡 提交于 2019-12-03 14:51:25
I am looking for some way to dynamically map database tables classes in my application using nhibernate (or if some other ORM works then let me know). I am fairly new to nhibernate, I used entity frameworks in the past though. Most of my application will be using a static structures and fluent nhibernate to map them. However there are multiple database tables that will be needed to be created and mapped to objects at each install site. These will all have as a base structure (id,name etc) however they will have additional fields depending on the type of data they are capturing. From some

Private property mapping with fluent nhibernate

元气小坏坏 提交于 2019-12-03 14:15:29
I am getting exception mapping a private property.This is the situation: I have this in Entity.cs: privat int m_Inactive; and in EntityMap.cs I have : Map(x => Reveal.Property<Entity>("m_Inactive")).ColumnName.("INACTIVE"); But I get this error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Not a member access What could be the reason? Thanks. If you follow the examples on the wiki you'll see that you're supposed to use Map(Reveal.Member<YourEntity>("m_Inactive")) . Looks like in the latest version you're