fluent-nhibernate

fluent nhibernate PrimaryKeyConvention for property names

纵饮孤独 提交于 2019-12-11 15:32:44
问题 This question has been asked already but there was no decent answer. Is there a property name convention for fluent nhibernate so that instead of looking for Id it looks for ProductId ? PrimaryKeyConvention applies to the column names in the database, NOT the property names. Consider this scenario: public class Product { public int ProductId { get; set; } public string Name { get; set; } } public class AutomappingConfiguration : DefaultAutomappingConfiguration { public override bool ShouldMap

nHibernate Eager Loading at runtime

早过忘川 提交于 2019-12-11 15:23:45
问题 We're using NCommon's UnitOfWorkScope which wraps nHibernate ISession functionality. Our goal is to eager-load complex properties on demand vs. always eagerly loading them via configuration. The idea is that a given service that retrieves an entity can be customized a bit by the calling code - sometimes we want only the parent entity to be hydrated, other times we may want the complex child properties hydrated, too. To accomplish this, we're doing the following: var iSession = unitOfWorkScope

how to keep many to many relationships in sync with nhibernate?

独自空忆成欢 提交于 2019-12-11 14:36:54
问题 I am creating data model for two objects Employee and Department. Employee has a list of departments and Department has a list of employees. class Employee{ private IList<Department> _departments; public Employee() { _departments = new List<Department>(); } public virtual ReadOnlyCollection<Department> Departments{ get {return new ReadOnlyCollection<Department>(_departments);} } } class Department{ private IList<Employee> _employees; public Department() { _departments = new List<Employee>();

(Fluent) NHibernate - problem mapping Id

二次信任 提交于 2019-12-11 12:51:53
问题 I have a problem mapping an Id. The structures of the entities are as follows: public abstract class Entity<TEntity, TId> where TEntity : Entity<TEntity, TId> { public virtual TId Id { get; protected set; } public override bool Equals(object obj)... ... } public class EntityA<EntityA, long> : Entity<EntityA, long> { public virtual EntityB B { get; private set; } /* ... */ } public class EntityB<EntityA, long> : Entity<EntityB, long> { /* ... */ } In my model, every EntityA must contain

How should AutoMapper access my DAL?

感情迁移 提交于 2019-12-11 12:37:39
问题 I have an InvoiceInputModel with a ProjectId property which is a reference to a Project entity. Ideally, I want AutoMapper to be able to map an entire Invoice entity from an InvoiceInputModel , which looks like this: public class InvoiceInputModel { public Guid Id { get; set; } public DateTime Date { get; set; } public string Reference { get; set; } public Guid ProjectId { get; set; } } Obviously the following is bad: Mapper.CreateMap<InvoiceInputModel, Invoice>() .ForMember(src => src

How to use NHibernate ManyToMany with properties (columns) on Join Table (Fluent NHibernate)

陌路散爱 提交于 2019-12-11 12:18:50
问题 I have the following classes that I need NHibernate to play nicely with. How do I do it? public class Customer { public int ID { get; set; } public string Name {get;set;} } public class Product { public int ID { get; set; } public string Name {get;set;} } public class CustomerPricing { public int ID { get; set; } public decimal Price {get;set;} public Customer Customer { get; set; } public Product Product {get;set;} public datetime ExpiresOn { get; set; } public string ApprovedBy {get;set;} }

Many entities to one junction table NHibernate modelling

邮差的信 提交于 2019-12-11 11:53:58
问题 I would like to be able to add a collection of Notes to any of my main entities in my NHibernate application. I can see how you could do this with a seperate junction table per entity. However, I would like to be able to avoid this and only have one junction table - if this is possible. Below is the code so far, however this will result in all Notes being loaded for every Entity and I only want to load the notes for that particular entity. What are the alternative approaches I need to take?

Possible to use CustomSqlType with CompositeId?

淺唱寂寞╮ 提交于 2019-12-11 11:52:10
问题 Working with legacy tables, need to create a CompositeId based on two char(3) fields. Don't see any overloads that make this possible with Fluent. The mapping I'm attempting looks like this: CompositeId() .KeyProperty(x => x.LegacyEntity1Id, "LegacyEntity1Id") .KeyProperty(x => x.LegacyEntity2Id, "LegacyEntity2Id"); Map(x => x.LegacyEntity1Id).CustomSqlType("char(3)"); Map(x => x.LegacyEntity2Id).CustomSqlType("char(3)"); I've also tried: CompositeId() .KeyReference(x => x.LegacyEntity1,

Composite keys fluent nhibernate

故事扮演 提交于 2019-12-11 11:45:52
问题 Can one do this on a fluent nhibernate ? When I try to save, I am profiding the profile and the scenario objects and the id's are not null. Nhibernate complains that it can't insurt NULL for ProfileID column. Fluent Nhibernate doesn't know how to get to the Profile.ID ? CompositeId().KeyProperty(x => x.Profile.ID, "ProfileID").KeyProperty(x => x.Scenario.ID, "ScenarioID"); 回答1: You should probably use this instead: CompositeId() .KeyReference(x => x.Profile, "ProfileID") .KeyReference(x => x

Map composite key with unmapped column

我们两清 提交于 2019-12-11 11:23:08
问题 How do I map a composite key, if part of it is not mapped in my entity? Example: I have a table ITEMDELIVERY containing the columns: ITEMDELIVERY_ID (PK) DELIVERY_DATE (PK) I have a table ITEMDELIVERYDETAIL containing the columns: ITEMDELIVERYDETAIL_ID (PK) ITEMDELIVERY_ID (FK) PARTITIONDATE (PK, FK) As you can see, there is a composite key in both tables and ITEMDELIVERYDETAIL has a "composite" foreign key to ITEMDELIVERY . There exists no property PartitionDate in my domain model