fluent-nhibernate

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

Nhibernate QueryOver JoinAlias UnRelated Entity

♀尐吖头ヾ 提交于 2019-12-02 04:42:41
I have an issue in NHibernate regarding a left join using "JoinAlias" when the result query SQL that I am looking for is this : "select * from EntityA T1 left join EntityB T2 on T2.EntityAId=T1.id" And in NHibernate I have this but doesn't work: var query = _session.QueryOver(() => EntityA) .Left.JoinAlias(() => EntityA, () => EntityB.EntityA) In NHibernate EntityA doesn't reference to EntityB but EntityB as a reference to EntityA . public class EntityA { public int Id {get;set;} } public class EntityB { public int Id {get;set;} public EntityA EntityA {get;set;} } How can I make this very

How implement the Open Session in View pattern in NHibernate?

我的未来我决定 提交于 2019-12-02 04:25:38
I'm using ASP.NET MVC + NHibernate + Fluent NHibernate and having a problem with lazy loading. Through this question ( How to fix a NHibernate lazy loading error "no session or session was closed"? ), I've discovered that I have to implement the Open Session in View pattern , but I don't know how. In my repositories classes, I use methods like this public ImageGallery GetById(int id) { using(ISession session = NHibernateSessionFactory.OpenSession()) { return session.Get<ImageGallery>(id); } } public void Add(ImageGallery imageGallery) { using(ISession session = NHibernateSessionFactory

Map table with composite key / foreign key to that table

自古美人都是妖i 提交于 2019-12-02 03:43:29
I am trying to map a table that has a composite key and map another table that references this table. Assume these tables: ITEMDELIVERY with relevant columns: ITEMDELIVERY_ID DELIVERY_DATE ITEMDELIVERYDETAIL with relevant columns: ITEMDELIVERYDETAIL_ID ITEMDELIVERY_ID PARTITIONDATE The columns ITEMDELIVERY.ITEMDELIVERY_ID and ITEMDELIVERY.DELIVERY_DATE together form the PK. The columns ITEMDELIVERYDETAIL.ITEMDELIVERY_ID and ITEMDELIVERYDETAIL.PARTITIONDATE form the FK from ITEMDELIVERYDETAIL to ITEMDELIVERY . How do I map this? I tried the following: IAutoMappingOverride<ItemDeliveryDetail> :

Fluent nHibernate: Need help with ManyToMany Self-referencing mapping

独自空忆成欢 提交于 2019-12-02 03:27:47
问题 I have an entity called User which can have a list of other Users called Friends (kinda like Facebook). In my User entity, I've delcared a public virtual IList Friends { get; private set;} property, and an creating the list in the constructor. I also have an "AddFriends" method that adds Users to the Friends list. In my UserMapping class I have the following code to map the relationship HasManyToMany(x => x.Friends) .ParentKeyColumn("UserId") .ChildKeyColumn("FriendId") .Table("UserFriends")

How can the NamedSQLQueryDefinition class be used dynamically as a sql-query equivalent?

試著忘記壹切 提交于 2019-12-02 03:15:44
I need to dynamically add named queries to the NHibernate configuration object. The search engines return few hits referencing NamedSQLQueryDefinition or NamedQueryDefinition. Below is what I'm attempting to do. I don't know what to provide to the NamedSQLQueryDefinition constructor to successfully create a query. Can anyone provide a sample of how to create a new NamedSQLQueryDefinition the right way? Thanks!! Session initializer: private static ISessionFactory CreateSessionFactory() { var configuration = new Configuration(); return Fluently.Configure(configuration.Configure())

mapping nhibernate parent/child relationship the 'other' way round

岁酱吖の 提交于 2019-12-02 03:00:15
问题 using FluentNhibernate; I am trying to persist a seemingly simple object model: public class Product { public int Id { get; set; } public string Name { get; set; } public Config Config { get; set; } } public class Config { public int ConfigId { get; set; } public int ProductId { get; set; } public string ConfigField1 { get; set; } public string ConfigField2 { get; set; } } and the database looks like: (not syntactically correct) CREATE TABLE [dbo].[Products]( [ProductId] [int] IDENTITY(1,1)

mapping nhibernate parent/child relationship the 'other' way round

∥☆過路亽.° 提交于 2019-12-02 02:38:45
using FluentNhibernate; I am trying to persist a seemingly simple object model: public class Product { public int Id { get; set; } public string Name { get; set; } public Config Config { get; set; } } public class Config { public int ConfigId { get; set; } public int ProductId { get; set; } public string ConfigField1 { get; set; } public string ConfigField2 { get; set; } } and the database looks like: (not syntactically correct) CREATE TABLE [dbo].[Products]( [ProductId] [int] IDENTITY(1,1) NOT NULL, [Name] [varchar](50) NULL ) CREATE TABLE [dbo].[Config]( [ConfigId] [int] IDENTITY(1,1) NOT

Nhibernate Lazy Load exception after a view exception

烂漫一生 提交于 2019-12-02 02:38:40
问题 I get a weird behavior with NHibernate with Fluent Configuration. Whenever a generic exception unrelated to the NHibernate occurs i.e. in the view a DivideByZeroException every request after the exception throws. An exception of type 'NHibernate.LazyInitializationException' occurred in NHibernate.dll but was not handled in user code. Additional information: Initializing[Entity]-Could not initialize proxy - no Session. Due to nature of the bug the bug is critical due to the fact that 1 user

Fluent Nhibernate AutoMapping — 2 foreign keys to same table?

牧云@^-^@ 提交于 2019-12-02 02:36:54
Let say I'm doing a basic transaction system where I have the following objects. public class User { public virtual int Id{get; set;} } public class Transaction { public virtual int Id{get; set;} public virtual Item Item {get; set;} public virtual User Seller{get; set;} public virtual User Buyer{get; set;} } Notice how I have two relationships back to the User object. When FHN generates the table schema I get 3 FK relationships from the transaction table back to the User table, "Buyer_id", "Seller_id", "User_id" I think it's auto generating the "User_id" field erroneously based on the fact it