fluent-nhibernate

Accept Interface into Collection (Covariance) troubles with nHibernate

自闭症网瘾萝莉.ら 提交于 2019-12-02 07:31:58
I am using Fluent nHibernate for my persistence layer in an ASP.NET MVC application, and I have come across a bit of a quandry. I have a situation where I need to use an abstraction to store objects into a collection, in this situation, an interface is the most logical choice if you are looking at a pure C# perspective. Basically, an object ( Item ) can have Requirements . A requirement can be many things. In a native C# situation, I would merely accomplish this with the following code. interface IRequirement { // methods and properties neccessary for evaluation } class Item { virtual int Id {

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

Fluent NHibernate 1.1: when multiple column name mappings are used on different classes

天大地大妈咪最大 提交于 2019-12-02 07:25:18
Suppose I have this (simplified) Class Cliente Id(v => v.numero_cliente, "numero_cliente") HasMany(v => v.Acionamentos).Cascade.All().LazyLoad() Class Movimentacao References(v => v.Cliente, "id_Fornecedor") Class Acionamento References(v => v.Cliente, "numero_cliente") Fluent nHibernate will generate wrong SQL, for example: If i try to get Acionamentos,then it will throw an incorrect SQL: SELECT * FROM Acionamentos WHERE id_Fornecedor =p0 But on my Acionamento Mapping i set an reference to a column named numero_cliente and not to id_Fornecedor If I use always the same column name "numero

Finding the Primary Key from a ClassMap<T>

自作多情 提交于 2019-12-02 07:22:12
With Fluent NHibernate , I have an arbitrary ClassMap<T> , I want to be able to find out what property (if any) was set as the primary key . Example: public class PersonMap : ClassMap<Person> { public PersonMap() { Id(p => p.StupidPrimaryKeyId).GeneratedBy.Identity().Column("StupidPrimaryKeyId"); } } ... //usage MemberInfo primaryKeyMember = FindPrimaryKey(new PersonMap()); Can anybody tell me what the method body for FindPrimaryKey would have to be in order to return StupidPrimaryKeyId ? Edit: 1/10/12 I originally wanted this because I wanted to know whether or not a detached entity existed

Fluent NHibernate join tables in mapping not using primary key

核能气质少年 提交于 2019-12-02 07:21:49
问题 I'm trying to create one entity from 2 tables that are related not by primary key Tables: CREATE TABLE [employees]( [ssn] [nvarchar](9) NULL, [active] [bit] NULL, [employee_id] [int] IDENTITY(1,1) NOT NULL ) CREATE TABLE [sam_employees]( [ssn] [nvarchar](9) NULL, [first_name] [nvarchar](50) NULL, [last_name] [nvarchar](50) NULL, [skill] [nvarchar](50) NULL, .... ) SQL to generate: SELECT this_.employee_id as employee1_0_0_, this_.ssn as ssn0_0_, this_.active as active0_0_, this_1_.first_name

NHibernate HQL Inner Join (SQL Server,Visual C#)

假如想象 提交于 2019-12-02 07:19:27
I want to using HQL with inner Join. But, a query syntax exception is thrown. This is my C# code: string sqlQuery = "Select fq FROM Answers as fq INNER JOIN Questions as q " + " on fq.questionId=q.questionId"; IList Result; int count = 0; try { using (ISession session = ConnectionModule.OpenSession()) { IQuery query = session.CreateQuery(sqlQuery); session.CreateCriteria(typeof(Answers)); Result = query.List(); } } catch(Exception ex) { MessageBox.Show(ex.Message+"\n"+ex.InnerException); } The point here is CROSS JOIN if there are no mapped relations, JOIN on existing (mapped) relations. So,

Fluent NHibernate Mapping a column against one of two columns

筅森魡賤 提交于 2019-12-02 06:57:46
问题 I'm dealing with some legacy vendor code that I can't modify. I'd like to wrap the database with an abstraction layer that is easier to use. Given the following two tables, I need to create a mapping for Process.Route that will find the matching Route for a given Process, but that can be either dbo.Route.SourceProcessID or dbo.Route.DestinationProcessID: TABLE [dbo].[Route]( [RouteID] [bigint] IDENTITY(1,1) NOT NULL, [SourceProcessID] [bigint] NOT NULL, [DestinationProcessID] [bigint] NOT

using fluent-nhibernate and traditionally hbm.xml together

风格不统一 提交于 2019-12-02 06:57:26
So far I used this code to configure a session factory: Configuration configuration = new Configuration(); configuration.Configure(); SessionFactory = configuration.BuildSessionFactory(); Now I added some fluentNhibernate mapping classes, and used this code to configure: Configuration configuration = new Configuration(); configuration.Configure(); SessionFactory = configuration.BuildSessionFactory(); SessionFactory = Fluently.Configure(configuration).Mappings(m => { m.FluentMappings.AddFromAssemblyOf<AttachmentLocaionMap>(); m.FluentMappings.AddFromAssemblyOf<AttachmentTypeMap>(); m

NHibernate: Load base class objects only

别等时光非礼了梦想. 提交于 2019-12-02 06:07:44
问题 Any kind of help is welcome. Even if you can say (based upon your experience) that using an ORM for such a huge hierarchy is insane :). Backgroud My model layer has a pretty huge class hierarchy i.e. there are around 200 classes. The good/bad thing with hierarchy is that all of them have the same base class. The maximum distance between the base and leaf classes is 7 and the maximum number classes at any level in hierarchy is 80. I am using nHibernate to save/load data from persistent storage

Fluent NHibernate join tables in mapping not using primary key

我的未来我决定 提交于 2019-12-02 05:00:33
I'm trying to create one entity from 2 tables that are related not by primary key Tables: CREATE TABLE [employees]( [ssn] [nvarchar](9) NULL, [active] [bit] NULL, [employee_id] [int] IDENTITY(1,1) NOT NULL ) CREATE TABLE [sam_employees]( [ssn] [nvarchar](9) NULL, [first_name] [nvarchar](50) NULL, [last_name] [nvarchar](50) NULL, [skill] [nvarchar](50) NULL, .... ) SQL to generate: SELECT this_.employee_id as employee1_0_0_, this_.ssn as ssn0_0_, this_.active as active0_0_, this_1_.first_name as first2_1_0_, this_1_.last_name as last3_1_0_, this_1_.skill as skill1_0_ FROM employees this_ inner