fluent-nhibernate-mapping

Fluent NHibernate HasMany Foreign Key Mapping Problem

萝らか妹 提交于 2019-12-03 03:54:19
I'm trying to map a simple data structure in nhibernate Tables: Employees employeeID int username varchar(30) departmentID int Departments departmentID int deptName varchar(50) My department mapping is like so: public class DepartmentMap: ClassMap<Department> { public DepartmentMap() { Id(m => m.DepartmentID).Column("departmentID"); Map(m => m.DepartmentName).Column("deptName").Length(50); HasMany(m => m.Employees); Table("Departments"); } } ... and the employee mapping public class EmployeeMap : ClassMap<Employee> { public EmployeeMap() { Id(x => x.EmployeeID, "employeeID"); Map(x => x

Fluent Nhibernate Many to Many Mapping Way

只谈情不闲聊 提交于 2019-12-03 02:08:41
I have two classes Order and Items I want a method like this class Order { public virtual IList<Item> GetItems(Order order) { //get items for that order. } } class Item { public virtual IList<Order> GetOrders(Item item) { //get all the orders in which that items is present. } } Is it write to create a method like this or instead should I create a property public virtual IList<Item> Items { get; set; } And how should I do the mapping for this is nhibernate?? Apparently you have a many-to-many relationship: An order can have many items and an item can belong to many orders. In a relational

Bi-directional relationship in nhibernate 4.0

妖精的绣舞 提交于 2019-12-02 17:49:03
问题 I have a code that was working perfectly on NHibernate 3.1, but when it is not working on NHibernate 4.0 So, this is the class relations public class Employee : BaseEntity { ... public Department Dept { get; set; } } public class Department : BaseEntity { ... public IList<Employee> Employees { get; set; } } and for the mapping we have this DepartmentMap : ClassMap<Department> { Table("...."); HasMany(x => x.Employees).KeyColumn("DeptId").Not.KeyNullable(); } EmployeeMap : ClassMap<Employee> {

NHibernate Criteria with Distinct Parent Load All Children?

一个人想着一个人 提交于 2019-12-02 14:44:59
问题 I have a parent child relationship where I want to return only one parent and load all the children. I am using criteria because it is a dynamic query. var messageQueueId = this.GetPropertyName<MessageQueue>(x => x.Id); var query = _sessionManager.Session.CreateCriteria<MessageQueue>(QUEUE_ALIAS); query.SetFirstResult(_pageOffset); query.SetMaxResults(_pageSize); query.Add(Restrictions.In(messageQueueId, _messageQueueIds)); query.List<MessageQueue>(); This returns the parent (MessageQueue)

NHibernate Prevent Lazy Loading of unmatched reference

安稳与你 提交于 2019-12-02 11:06:13
问题 I have quite a problem with NHibernate. I have a reference from Table1 to Table2, and I want NHibernate to, when a corresponding record is not found in Table2, to not then issue a SELECT statement against Table2, to, I don't know, make really really sure that it actually isn't there. I've tried adding modifiers like .LazyLoad(Laziness.False) and .NotFound.Ignore() to my reference, but NHibernate gaily ignores my commands with extreme prejudice, issuing its select and breaking my code. 回答1: It

NHibernate Fluent Add external Assembly mappings

。_饼干妹妹 提交于 2019-12-02 10:51:46
I have a project with my mappings and entities stored in other class libraries and NHibernate layers in another project. In my testing project I would like to add these mapping via fluently configure... Mappings... via assebly and not individually. In my code below you can see I added just one entity.. But I would like to configure it to scan my other assemblies. I am sure I am just missing the obvious here.. any pointers would be greatly appreciated... [Test] public void Can_generate_schemaFluently() { var cfg = new Configuration(); cfg.Configure(); Configuration configuration = null;

NHibernate Criteria with Distinct Parent Load All Children?

只谈情不闲聊 提交于 2019-12-02 07:29:44
I have a parent child relationship where I want to return only one parent and load all the children. I am using criteria because it is a dynamic query. var messageQueueId = this.GetPropertyName<MessageQueue>(x => x.Id); var query = _sessionManager.Session.CreateCriteria<MessageQueue>(QUEUE_ALIAS); query.SetFirstResult(_pageOffset); query.SetMaxResults(_pageSize); query.Add(Restrictions.In(messageQueueId, _messageQueueIds)); query.List<MessageQueue>(); This returns the parent (MessageQueue) but not it's children (SearchMatches). When I try to do this: var query = _sessionManager.Session

NHibernate Prevent Lazy Loading of unmatched reference

耗尽温柔 提交于 2019-12-02 04:56:52
I have quite a problem with NHibernate. I have a reference from Table1 to Table2, and I want NHibernate to, when a corresponding record is not found in Table2, to not then issue a SELECT statement against Table2, to, I don't know, make really really sure that it actually isn't there. I've tried adding modifiers like .LazyLoad(Laziness.False) and .NotFound.Ignore() to my reference, but NHibernate gaily ignores my commands with extreme prejudice, issuing its select and breaking my code. Radim Köhler It is correct, that NHibernate tries to load "not existing". It must do that. As stated here

Mapping entity oneToMany with fluent nhibernate

邮差的信 提交于 2019-12-02 01:32:15
问题 The problem appears to be simple however I'm having so much trouble trying to map this entities. I just can't see what am I doing wrong. Can you guys help me? I have the class Cliente : public class Cliente { public Cliente () { } public virtual int ClienteId { get; set; } public IList<Medidor> ListaMedidores { get; set; } public virtual string NumeroMedidor { get; set; } } And class Medidor public class Medidor { public Medidor() { } public virtual string NumeroMedidor { get; set; } public

Limit collection to retrieve only recent entries for readonly entity

爷,独闯天下 提交于 2019-12-02 00:36:04
问题 The User entity can have thousands of UserOperations. Sometimes I don't want to retrieve (for readonly entity) all of them but only "the recent 10 OR not completed". public class SimpleForm { public class User : EntityBase { // ... private ISet<UserOperation> _recentOperations = new HashedSet<UserOperation>(); public virtual ISet<UserOperation> RecentOperations { get { return _recentOperations; } set { _recentOperations = value; } } } } So how can I specify it? I think I could use mapping