Search Results

Search found 1981 results on 80 pages for 'fluent nhibernate'.

Page 19/80 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • Fluent NHibernate - Delete a related object when no explicit relationship exists in the model

    - by John Price
    I've got an application that keeps track of (for the sake of an example) what drinks are available at a given restaurant. My domain model looks like: class Restaurant { public IEnumerable<RestaurantDrink> GetRestaurantDrinks() { ... } //other various properties } class RestaurantDrink { public Restaurant Restaurant { get; set; } public Drink { get; set; } public string DrinkVariety { get; set; } //"fountain drink", "bottled", etc. //other various properties } class Drink { public string Name { get; set; } public string Manufacturer { get; set; } //other various properties } My db schema is (I hope) about what you'd expect; "RestaurantDrinks" is essentially a mapping table between Restaurants and Drinks with some extra properties (like "DrinkVariety" tacked on). Using Fluent NHibernate to set up mappings, I've set up a "HasMany" relationship from Restaurants to RestaurantDrinks that causes the latter to be deleted when its parent Restaurant is deleted. My question is, given that "Drink" does not have any property on it that explicitly references RestaurantDrinks (the relationship only exists in the underlying database), can I set up a mapping that will cause RestaurantDrinks to be deleted if their associated Drink is deleted?

    Read the article

  • How to fine tune FluentNHibernate's auto mapper?

    - by Venemo
    Okay, so yesterday I managed to get the latest trunk builds of NHibernate and FluentNHibernate to work with my latest little project. (I'm working on a bug tracking application.) I created a nice data access layer using the Repository pattern. I decided that my entities are nothing special, and also that with the current maturity of ORMs, I don't want to hand-craft the database. So, I chose to use FluentNHibernate's auto mapping feature with NHibernate's "hbm2ddl.auto" property set to "create". It really works like a charm. I put the NHibernate configuration in my app domain's config file, set it up, and started playing with it. (For the time being, I created some unit tests only.) It created all tables in the database, and everything I need for it. It even mapped my many-to-many relationships correctly. However, there are a few small glitches: All of the columns created in the DB allow null. I understand that it can't predict which properties should allow null and which shouldn't, but at least I'd like to tell it that it should allow null only for those types for which null makes sense in .NET (eg. non-nullable value types shouldn't allow null). All of the nvarchar and varbinary columns it created, have a default length of 255. I would prefer to have them on max instead of that. Is there a way to tell the auto mapper about the two simple rules above? If the answer is no, will it work correctly if I modify the tables it created? (So, if I set some columns not to allow null, and change the allowed length for some other, will it correctly work with them?) EDIT: I managed to achieve the above by using Fluent NHibernate's convention API. Thanks to everyone who helped! However, there is one more thing: after checking out the convention API, I really would like my IDs to be calld "ID", not "Id", but it seems to me that the PrimaryKey.Name.Is(x => "ID") is not working at all. If I add it to the conventions collection and rewrite my entities' properties to "ID" instead of "Id", it throws an exception that there is no primary key mapped. Any thoughts on this?

    Read the article

  • NHibernate unintentional lazy property loading

    - by chiccodoro
    I introduced a mapping for a business object which has (among others) a property called "Name": public class Foo : BusinessObjectBase { ... public virtual string Name { get; set; } } For some reason, when I fetch "Foo" objects, NHibernate seems to apply lazy property loading (for simple properties, not associations): The following code piece generates n+1 SQL statements, whereof the first only fetches the ids, and the remaining n fetch the Name for each record: ISession session = ...IQuery query = session.CreateQuery(queryString); ITransaction tx = session.BeginTransaction(); List<Foo> result = new List<Foo>(); foreach (Foo foo in query.Enumerable()) { result.Add(foo); } tx.Commit(); session.Close(); produces: NHibernate: select foo0_.FOO_ID as col_0_0_ from V1_FOO foo0_<br/> NHibernate: SELECT foo0_.FOO_ID as FOO1_2_0_, foo0_.NAME as NAME2_0_ FROM V1_FOO foo0_ WHERE foo0_.FOO_ID=:p0;:p0 = 81<br/> NHibernate: SELECT foo0_.FOO_ID as FOO1_2_0_, foo0_.NAME as NAME2_0_ FROM V1_FOO foo0_ WHERE foo0_.FOO_ID=:p0;:p0 = 36470<br/> NHibernate: SELECT foo0_.FOO_ID as FOO1_2_0_, foo0_.NAME as NAME2_0_ FROM V1_FOO foo0_ WHERE foo0_.FOO_ID=:p0;:p0 = 36473 Similarly, the following code leads to a LazyLoadingException after session is closed: ISession session = ... ITransaction tx = session.BeginTransaction(); Foo result = session.Load<Foo>(id); tx.Commit(); session.Close(); Console.WriteLine(result.Name); Following this post, "lazy properties ... is rarely an important feature to enable ... (and) in Hibernate 3, is disabled by default." So what am I doing wrong? I managed to work around the LazyLoadingException by doing a NHibernateUtil.Initialize(foo) but the even worse part are the n+1 sql statements which bring my application to its knees. This is how the mapping looks like: <class name="Foo" table="V1_FOO"> ... <property name="Name" column="NAME"/> </class> BTW: The abstract "BusinessObjectBase" base class encapsulates the ID property which serves as the internal identifier.

    Read the article

  • Fluent NHibernate Mappings ClassMap<Entities>....

    - by Pandiya Chendur
    I was going through fluent hibernate getting started tutorial.... In my asp.net mvc web application i have created Entities and Mapping folder as they stated... I created an entity class and i tried to map it my mapping class using this, using System; using System.Collections.Generic; using System.Linq; using System.Web; using FluentNhibernateMVC.Entities; namespace FluentNhibernateMVC.Mappings { public class ClientMap : ClassMap<Client> { } } I cant able to find a ClassMap keyword in my autosuggest list why? This is my entity class using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace FluentNhibernateMVC.Entities { public class Client { public int ClientId { get; set; } public string ClientName { get; set; } public string ClientMobNo { get; set; } public string ClientAddress { get; set; } public DateTime CreatedDate { get; set; } public byte IsDeleted { get; set; } public int CreatedBy { get; set; } } } I have added all references to my project...Am i missing some thing...

    Read the article

  • How to create a reference tables for collection classes using fluent nhibernate

    - by Akk
    How can i create a 3 table schema from the following model classes. public class Product { public int Id {get; set;} public string Name {get; set;} public IList<Photo> Photos {get; set;} } public class Photo { public int Id {get; set;} public string Path {get; set;} } I want to create the following table structure in the database: Product ------- Id Name ProductPhotos ------------- ProductId (FK Products.Id) PhotoId (FK Photos.Id) Photos ------ Id Path How i can express the above Database Schema using Fluent NHibernate? I could only manage the following the Mapping but this does not get me the 3rd Photo ref table. public class ProductMap : ClassMap<Product> { public CityMap() { Id(x => x.Id); Map(x => x.Name); Table("Products"); HasMany(x => x.Photos).Table("ProductPhotos").KeyColumn("ProductId"); } }

    Read the article

  • How to create reference tables using fluent nhibernate

    - by Akk
    How can i create a 3 table schema from the following model classes. public class Product { public int Id {get; set;} public string Name {get; set;} public IList<Photo> Photos {get; set;} } public class Photo { public int Id {get; set;} public string Path {get; set;} } I want to create the following table structure in the database: Product ------- Id Name ProductPhotos ------------- ProductId (FK Products.Id) PhotoId (FK Photos.Id) Photos ------ Id Path How i can express the above Database Schema using Fluent NHibernate? I could only manage the following the Mapping but this does not get me the 3rd Photo ref table. public class ProductMap : ClassMap<Product> { public CityMap() { Id(x => x.Id); Map(x => x.Name); Table("Products"); HasMany(x => x.Photos).Table("ProductPhotos").KeyColumn("ProductId"); } }

    Read the article

  • fluent nhibernate - storing and retrieving three classes in/from one table

    - by Will I Am
    Noob question. I have this situation where I have these objects: class Address { string Street; string City; ... } class User { string UserID; Address BillingAddress; Address MailingAddress; ... } What is the proper way of storing this data using (fluent) nHibernate? I could use a separate Address table and create a reference, but they are 1:1 relationships so I don't really want to incur the overhead of a join. Ideally I would store this as a single flat record. So, my question is, what is the proper way of storing an instance of class 'User' in such a way that it stores its contents and also the two addresses as a single record? My knowledge is failing me on how I can store this information in such a way that the two Address records get different column names (e.g. BillingAddress_Street and MailingAddress_Street, for example), and also how to read a record back into a User instance.

    Read the article

  • SQLite NHibernate configuration with .Net 4.0 and vs 2010

    - by Berryl
    I am having way too much trouble getting my environment straight after switching to 2010 and .net 4.0, so I'd like to break the whole process down once and for all. 1) Which SQLite dll?? I think it is SQLite-1.0.65.1-vs2010rc-net4-setup.zip. Yes? 2) I ran the installer so the dll is in the GAC but I usually find there are less problems if I can just reference the dll stand alone. Is there any reason it needs to be in the GAC, and if not, what's the best way to uninstall it from the GAC (I can get to the GAC folder but it says I need permission to delete the files; should I leave the SQLite Designer dll's there?)? 3) x64. There is an x64 dll in the download. I had problems with SQLite in the past though that I could only resolve by compiling to x86. Can I safely reference the x64 dll and compile to Any CPU now? 4) what is the right NHib config? I have been using the one below, but since the error I get says "Could not create the driver from NHibernate.Driver.SQLite20Driver." that configuration is guilty until proven innocent too? 5) could FNH be a problem too? I don't use the pre-configured fluent SQLite method but FNH has to provide a reference to it for that to work, no? TIA & Cheers, Berryl <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> ... <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> <property name="connection.connection_string">Data Source=:memory:;Version=3;New=True;</property> .... </hibernate-configuration>

    Read the article

  • Using Doctype in Nhibernate

    - by sukh
    Hi I am trying to keep common properties of base class in one location and use XML ENTITY to refer in Nhibernate mapping file. Mapping file <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE hibernate-mapping [ <!ENTITY BasePropertyList SYSTEM "BasePropertyList.xml"> ]> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace= "Model" default-lazy="false"> <class name="DerivedClass"> &BasePropertyList; </class> </hibernate-mapping> BasePropertyList.xml <id name="ID" column="ID" type="Int32" unsaved-value="0"> <generator class="native"></generator> </id> <property name="CreatedDate" update="false" /> <property name="CreatedBy" update="false" /> <property name="LastModifiedDate" /> <property name="LastModifiedBy" /> I am getting following exception System.Xml.XmlException : DTD is prohibited in this XML document. at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) Am I missing anything here? How DOCTYPE works in Nhibernate mapping file??

    Read the article

  • How to get interpolated message in NHibernate.Validator

    - by SztupY
    Hi! I'm trying to integrate NHibernate.Validator with ASP.NET MVC client side validations, and the only problem I found is that I simply can't convert the non-interpolated message to a human-readable one. I thought this would be an easy task, but turned out to be the hardest part of the client-side validation. The main problem is that because it's not server-side, I actually only need the validation attributes that are being used, and I don't actually have an instance or anything else at hand. Here are some excerpts from what I've been already trying: // Get the the default Message Interpolator from the Engine IMessageInterpolator interp = _engine.Interpolator; if (interp == null) { // It is null?? Oh, try to create a new one interp = new NHibernate.Validator.Interpolator.DefaultMessageInterpolator(); } // We need an instance of the object that needs to be validated, se we have to create one object instance = Activator.CreateInstance(Metadata.ContainerType); // we enumerate all attributes of the property. For example we have found a PatternAttribute var a = attr as PatternAttribute; // it seems that the default message interpolator doesn't work, unless initialized if (interp is NHibernate.Validator.Interpolator.DefaultMessageInterpolator) { (interp as NHibernate.Validator.Interpolator.DefaultMessageInterpolator).Initialize(a); } // but even after it is initialized the following will throw a NullReferenceException, although all of the parameters are specified, and they are not null (except for the properties of the instance, which are all null, but this can't be changed) var message = interp.Interpolate(new InterpolationInfo(Metadata.ContainerType, instance, PropertyName, a, interp, a.Message)); I know that the above is a fairly complex code for a seemingly simple question, but I'm still stuck without solution. Is there any way to get the interpolated string out of NHValidator?

    Read the article

  • How do I do nested transactions in NHibernate?

    - by Gavin Schultz-Ohkubo
    Can I do nested transactions in NHibernate, and how do I implement them? I'm using SQL Server 2008, so support is definitely in the DBMS. I find that if I try something like this: using (var outerTX = UnitOfWork.Current.BeginTransaction()) { using (var nestedTX = UnitOfWork.Current.BeginTransaction()) { ... do stuff nestedTX.Commit(); } outerTX.Commit(); } then by the time it comes to outerTX.Commit() the transaction has become inactive, and results in a ObjectDisposedException on the session AdoTransaction. Are we therefore supposed to create nested NHibernate sessions instead? Or is there some other class we should use to wrap around the transactions (I've heard of TransactionScope, but I'm not sure what that is)? I'm now using Ayende's UnitOfWork implementation (thanks Sneal). Forgive any naivety in this question, I'm still new to NHibernate. Thanks! EDIT: I've discovered that you can use TransactionScope, such as: using (var transactionScope = new TransactionScope()) { using (var tx = UnitOfWork.Current.BeginTransaction()) { ... do stuff tx.Commit(); } using (var tx = UnitOfWork.Current.BeginTransaction()) { ... do stuff tx.Commit(); } transactionScope.Commit(); } However I'm not all that excited about this, as it locks us in to using SQL Server, and also I've found that if the database is remote then you have to worry about having MSDTC enabled... one more component to go wrong. Nested transactions are so useful and easy to do in SQL that I kind of assumed NHibernate would have some way of emulating the same...

    Read the article

  • NHibernate Oracle stored procedure problem

    - by Mr. Flint
    ------Using VS2008, ASP.Net with C#, Oracle, NHibernate---- I have tested my stored procedure. It's working but not with NHibernate. Here are the codes: Procedure : create or replace procedure ThanaDelete (id number) as begin delete from thana_tbl where thana_code = id; end Mapping File: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataTransfer" namespace="DataTransfer"> <class name="DataTransfer.Models.Thana, DataTransfer" table="THANA_TBL"> <id name="THANA_CODE" column="THANA_CODE" type="Int32" unsaved-value="0"> <generator class="native"> <param name="sequence"> SEQ_TEST </param> </generator> </id> <property name="THANA_NAME" column="THANA_NAME" type="string" not-null="false"/> <property name="DISTRICT_CODE" column="DISTRICT_CODE" type="Int32" not-null="false"/> <property name="USER_ID" column="USER_ID" type="string" not-null="false"/> <property name="TRANSACTION_DATE" column="TRANSACTION_DATE" type="Date" not-null="false"/> <property name="TRANSACTION_TIME" column="TRANSACTION_TIME" type="string" not-null="false"/> <sql-delete>exec THANADELETE ? </sql-delete> </class> </hibernate-mapping> error: Message: could not delete: [DataTransfer.Models.Thana#10][SQL: exec THANADELETE ?] Source: NHibernate Inner Exception System.Data.OracleClient.OracleException Message: ORA-00900: invalid SQL statement

    Read the article

  • How to use Nhibernate Validator + NHib component + ddl

    - by mynkow
    I just configured my NHibValidator. My NHibernate creates the DB schema. When I set MaxLenght="20" to some property of a class then in the database the length appears in the database column. I am doing this in the NHibValidator xml file. But the problem is that I have components and cannot figure out how to achieve this behaviour. The component is configured correctly in the Customer.hbm.xml file. EDIT: Well, I found that Hibernate Validator users had the same problem two years ago. http://opensource.atlassian.com/projects/hibernate/browse/HV-25 Is this an issue for NHibernate Validator or it is fixed. If it is working tell me how please. ----------------------------------------------------- public class Customer { public virtual string Name{get;set;} public virtual Contact Contacts{ get; } } ----------------------------------------------------- public class Contact { public virtual string Address{get;set;} } ----------------------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <nhv-mapping xmlns="urn:nhibernate-validator-1.0" namespace="MyNamespace" assembly="MyAssembly"> <class name="Customer"> <property name="Name"> <length max="20"/> </property> <property name="Contacts"> <notNull/> <valid/> </property> </class> </nhv-mapping> ----------------------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <nhv-mapping xmlns="urn:nhibernate-validator-1.0" namespace="MyNamespace" assembly="MyAssembly"> <class name="Contact"> <property name="Address"> <length max="50"/> <valid/> </property> </class> </nhv-mapping> -----------------------------------------------------

    Read the article

  • Using nHibernate to map two different data models to one entity model

    - by Dan
    I have two different data models that map to the same Car entity. I needed to create a second entity called ParkedCar, which is identical to Car (and therefore inherits from it) in order to stop nhibernate complaining that two mappings exists for the same entity. public class Car { protected Car() { IsParked = false; } public virtual int Id { get; set; } public bool IsParked { get; internal set; } } public class ParkedCar : Car { public ParkedCar() { IsParked = true; } //no additional properties to car, merely exists to support mapping and signify the car is parked } The only issue is that when I come to retrieve a Car from the database using the Criteria API like so: SessionProvider.OpenSession.Session.CreateCriteria<Car>() .Add(Restrictions.Eq("Id", 123)) .List<Car>(); The query brings back Car Entities that are from the ParkedCar data model. Its as if nhibernate defaults to the specialised entity. And the mappings are defiantly looking in the right place: <class name="Car" xmlns="urn:nhibernate-mapping-2.2" table="tblCar"> <class name="ParkedCar" xmlns="urn:nhibernate-mapping-2.2" table="tblParkedCar" > How do I stop this?

    Read the article

  • NHibernate lazy properties behavior?

    - by GeReV
    I've been trying to get NHibernate into development for a project I'm working on at my workplace. Since I have to put a strong emphasis on performance, I've been running a proof-of-concept stress test on an existing project's table with thousands of records, all of which contain a large text column. However, when selecting a collection of these records, the select statement takes a relatively long time to execute; apparently due to the aforementioned column. The first solution that comes to mind is setting this property as lazy: <property name="Content" lazy="true"/> But there seems to be no difference in the SQL generated by NHibernate. My question is, how do lazy properties behave in NHibernate? Is there some kind of type limitations I could be missing? Should I take a different approach altogether? Using HQL's new Class(column1, column2) approach works, but lazy properties sounds like a simpler solution. It's perhaps worth mentioning I'm using NHibernate 2.1.2GA with the Castle DynamicProxy. Thanks!

    Read the article

  • NHibernate not dropping foreign key constraints.

    - by Kendrick
    I'm new to NHibernate, so this is probably my mistake, but when I use: schema.Create(true, true); I get: SchemaExport [(null)]- There is already an object named 'XXX' in the database. System.Data.SqlClient.SqlException: There is already an object named 'XXX' in the database. I grabbed the SQL code nHibernate was using, ran it directly from MSSMS, and recieved similar errors. Looking into it, the generated code is not properly dropping the foreign key constraints. The drop looks like this: if exists (select 1 from sysobjects where id = OBJECT_ID(N'dbo[FK22212EAFBFE4C58]') AND parent_obj = OBJECT_ID('YYY')) alter table dbo.YYY drop constraint FK22212EAFBFE4C58 Doing a "select OBJECT_ID(N'dbo[FK22212EAFBFE4C58]')" I get null. If I take out the "dbo" (i.e. "select OBJECT_ID(N'[FK22212EAFBFE4C58]')") then the ID is returned. So, my question is, why is nHibernate adding the dbo, and why does that prevent the object from being returned (since the table owning the constraint is dbo.XXX) One of my mapping files: <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping namespace="CanineApp.Model" assembly="CanineApp.Model" xmlns="urn:nhibernate-mapping-2.2"> <class name="MedicalLog" table="MedicalLog" schema="dbo"> <id name="MedicalLogID" type="Int64"> <generator class="identity" /> </id> <property name="InvoiceAmount" type="Decimal" not-null="true" /> ... <many-to-one name="Canine" class="Canine" column="CanineID" not-null="true" fetch="join" /> <many-to-one name="TreatmentCategory" class="TreatmentCategory" column="TreatmentCategoryID" not-null="true" access="field.camelcase-underscore" /> </class> </hibernate-mapping>

    Read the article

  • Fluent NHibernate Mapping and Formulas/DatePart

    - by Alessandro Di Lello
    Hi There, i have a very simple table with a Datetime column and i have this mapping in my domain object. MyDate is the name of the datetime column in the DB. public virtual int Day { get; set; } public virtual int Month { get; set; } public virtual int Year { get; set; } public virtual int Hour { get; set; } public virtual int Minutes { get; set; } public virtual int Seconds { get;set; } public virtual int WeekNo { get; set; } Map(x => x.Day).Formula("DATEPART(day, Datetime)"); Map(x => x.Month).Formula("DATEPART(month, Datetime)"); Map(x => x.Year).Formula("DATEPART(year, Datetime)"); Map(x => x.Hour).Formula("DATEPART(hour, Datetime)"); Map(x => x.Minutes).Formula("DATEPART(minute, Datetime)"); Map(x => x.Seconds).Formula("DATEPART(second, Datetime)"); Map(x => x.WeekNo).Formula("DATEPART(week, Datetime)"); This is working all great .... but Week Datepart. I saw with NHProf the sql generating for a select and here's the problem it's generating all the sql correctly but for week datepart.. this is part of the SQL generated: ....Datepart(day, MyDate) ... ....Datepart(month, MyDate) ... ....Datepart(year, MyDate) ... ....Datepart(hour, MyDate) ... ....Datepart(minute, MyDate) ... ....Datepart(second, MyDate) ... ....Datepart(this_.week, MyDate) ... where this_ is the alias for the table that nhibernate uses. so it's treating the week keyword for the datepart stuff as a column or something like that. To clarify there's no column or properties that is called week. some help ? cheers Alessandro

    Read the article

  • Fluent NHibernate - subclasses with shared reference

    - by ollie
    Edit: changed class names. I'm using Fluent NHibernate (v 1.0.0.614) automapping on the following set of classes (where Entity is the base class provided in the S#arp Architecture framework): public class Car : Entity { public virtual int ModelYear { get; set; } public virtual Company Manufacturer { get; set; } } public class Sedan : Car { public virtual bool WonSedanOfYear { get; set; } } public class Company : Entity { public virtual IList<Sedan> Sedans { get; set; } } This results in the following Configuration (as written to hbm.xml): <class name="Company" table="Companies"> <id name="Id" type="System.Int32" unsaved-value="0"> <column name="`ID`" /> <generator class="identity" /> </id> <bag cascade="all" inverse="true" name="Sedans" mutable="true"> <key> <column name="`CompanyID`" /> </key> <one-to-many class="Sedan" /> </bag> </class> <class name="Car" table="Cars"> <id name="Id" type="System.Int32" unsaved-value="0"> <column name="`ID`" /> <generator class="identity" /> </id> <property name="ModelYear" type="System.Int32"> <column name="`ModelYear`" /> </property> <many-to-one cascade="save-update" class="Company" name="Manufacturer"> <column name="`CompanyID`" /> </many-to-one> <joined-subclass name="Sedan"> <key> <column name="`CarID`" /> </key> <property name="WonSedanOfYear" type="System.Boolean"> <column name="`WonSedanOfYear`" /> </property> </joined-subclass> </class> So far so good! But now comes the ugly part. The generated database tables: Table: Companies Columns: ID (PK, int, not null) Table: Cars Columns: ID (PK, int, not null) ModelYear (int, null) CompanyID (FK, int, null) Table: Sedan Columns: CarID (PK, FK, int, not null) WonSedanOfYear (bit, null) CompanyID (FK, int, null) Instead of one FK for Company, I get two! How can I ensure I only get one FK for Company? Override the automapping? Put a convention in place? Or is this a bug? Your thoughts are appreciated.

    Read the article

  • Mapping Enums to Database with NHibernate/Castle ActiveRecord

    - by Mike
    There's a few other posts on mapping Enums to the DB with ActiveRecord, but none of them answer my question. I have an enum called OrderState: public enum OrderState {InQueue, Ordered, Error, Cancelled} And I have the following property on the table: [Property(NotNull = true, SqlType = "orderstate", ColumnType = "DB.EnumMapper, WebSite")] public OrderState State { get { return state; } set { state = value; } } And I have the following type class: public class EnumMapper : NHibernate.Type.EnumStringType<OrderState> { public EnumMapper() { } public override NHibernate.SqlTypes.SqlType SqlType { get { return new NHibernate.SqlTypes.SqlType(DbType.Object); } } } Now this actually works the way I want, but the problem is I have tons of enums and I don't want to create a EnumMapper class for each one of them. Isn't there some way to just tell ActiveRecord to use DbType.Object for any enum? It seems to either want to be an integer or a string, but nothing else. This one's been driving me crazy for the last 2 hours.. Mike

    Read the article

  • NHibernate Session Management Advice

    - by Hugusta
    I need some advice on NHibernate Session Management for a C# WinForms application. I am currently porting an application to use NHibernate. I am also employing a UnitOfWork pattern as described in the link below; http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx My question relates to Sessions. Can you only have one session running per thread at all times? I have a scenario in which a Session (UnitOfWork) may be open for a form shown by the application but the user opens another form (i.e. Tools - Options) which I would like to have its own UnitOfWork. Clearly in this instance it would make more sense to open another Session for the "Tools - Options" form and not use the currently open session for the underlying form. Can we have a Dictionary of Sessions on the one thread? Any advice on session management is appreciated.

    Read the article

  • NHibernate's automatic (dirty checking) update behaviour - turning it off

    - by Andrew Bullock
    I've just discovered that if I get an object from an NHibernate session and change a property on object, NHibernate will automatically update the object on commit without me calling Session.Update(myObj)! I can see how this could be helpful, but as default behaviour it seems crazy! How can I stop this happening? Is this default NHib behaviour or something coming from Fluent NHibs AutoPersistenceModel? If there's no way to stop this, what do I do? Unless I'm missing the point this behaviour seems to create a right mess, violating my UoW. Im using NHibernate 2.0.1.4 and a Fluent NHib build from 18/3/2009 Edit, is this guy right with his answer? Edit: I've also read that overriding an Event Listener could be a solution to this. However, IDirtyCheckEventListener.OnDirtyCheck isn't called in this situation. Does anyone know which listener I need to override? Thanks Andrew

    Read the article

  • How does NHibernate handle cascade="all-delete-orphan"?

    - by Johannes Rudolph
    I've been digging around the NHibernate sources a little, trying to understand how NHibernate implements removing child elements from a collection. I think I've already found the answer, but I'd ideally like this to be confirmed by someone familiar with the matter. So far I've found AbstractPersistentCollection (base class for all collection proxies) has a static helper method called GetOrphans to find orphans by comparing the current collection with a snapshot. The existence of this method suggests NHibernate tries to find all oprhaned elements and then deletes them by key. Is this correct, in terms of the generated SQL?

    Read the article

  • Is Lazy Loading required for nHibernate?

    - by johnny
    It took me a long time but I finally got nHibernate's Hello World to work. It worked after I did "lazy loading." Honestly, I couldn't tell you why it all worked, but it did and now I am reading you don't need lazy loading. Is there a hello world that anyone has that is bare bones making nHibernate work? Do you have to have lazy loading? I ask because I would like to use nHibernate but I need to understand how things are working. Thank you. Do you know of a hello world that doesn't have so much overhead? Is it better to use lazy loading? EDIT: I am using asp.net 3.5. Web Application Project.

    Read the article

  • Nhibernate criteria query inserts an extra order by expression when using JoinType.LeftOuterJoin and Projections

    - by Aaron Palmer
    Why would this nhibernate criteria query produce the sql query below? return Session.CreateCriteria(typeof(FundingCategory), "fc") .CreateCriteria("FundingPrograms", "fp") .CreateCriteria("Projects", "p", JoinType.LeftOuterJoin) .Add(Restrictions.Disjunction() .Add(Restrictions.Eq("fp.Recipient.Id", recipientId)) .Add(Restrictions.Eq("p.Recipient.Id", recipientId)) ) .SetProjection(Projections.ProjectionList() .Add(Projections.GroupProperty("fc.Name"), "fcn") .Add(Projections.Sum("fp.ObligatedAmount"), "fpo") .Add(Projections.Sum("p.ObligatedAmount"), "po") ) .AddOrder(Order.Desc("fpo")) .AddOrder(Order.Desc("po")) .AddOrder(Order.Asc("fcn")) .List<object[]>(); SELECT this_.Name as y0_, sum(fp1_.ObligatedAmount) as y1_, sum(p2_.ObligatedAmount) as y2_ FROM fundingCategories this_ inner join fundingPrograms fp1_ on this_.fundingCategoryId = fp1_.fundingCategoryId left outer join projects p2_ on fp1_.fundingProgramId = p2_.fundingProgramId WHERE (fp1_.recipientId = 6 /* @p0 */ or p2_.recipientId = 6 /* @p1 */) GROUP BY this_.Name ORDER BY p2_.name asc, y1_ desc, y2_ desc, y0_ asc It is incorrectly putting the p2_name asc into the ORDER BY statement, and causing it to crash. This only happens when I use JoinType.LeftOuterJoin on my Projects criteria. Is this a known nhibernate bug? I'm using nhibernate 2.0.1.4000. Thanks for any insight.

    Read the article

  • Use a folder of xml files as data source for nhibernate

    - by Bart Van Eyndhoven
    I'm going to start writing NUnit tests for a few classes in my project. A certain number of these classes use data gathered through nhibernate from a sql server 2008 database. The part of the program I'm about to test is very specific (and complicated). Therefore I have made a folder of xml files. Combined, the xml files could result in the database structure. I mean each xml file corresponds to a table in the database. The data in the xml files is also consistent with the database. Is there a way to use this folder of xml files as data source for nhibernate? I mean: can I use nhibernate to gather my test data (wich I have specifically chosen) instead of data from the database? In this way, I could usefully test this component without corrrupting the (test) database for future tests.

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >