Search Results

Search found 4565 results on 183 pages for 'nhibernate mapping'.

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

  • 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

  • Automatic layout of manual network mapping

    - by Paul
    So I have a small business network mainly consisting of two routed layer-2 domains with a total of ca. 100 devices spread over ca. 2000m² production and office spaces. Typical problems to solve using the graph would be: Over what (cable) path is a PC connected to the server? Where to expect devices connected to a switch port? I want to generate a graph of the physical network topology: Nodes are endpoint devices, switch ports, wall outlets, patch panel ports etc. Edges are cable connections. Ideally, grouping edges (or segments) that pass through the same bundle could be grouped. Also I would like to augment the graph data with automatically gathered data (monitoring state, MAC address, Switch port <- MAC entries to build up parts of the map). At the moment I use graphviz for this inside a Confluence wiki like that: layout = "neato" overlap = scale subgraph { rankdir = "TB" subgraph cluster_r1pf1 { r1pf1 [label="{ Rack 1 PF 1 | { <p1>P1 | <p2>P2 | <p3>P3} }", shape=record] } subgraph cluster_switch1 { switch1 [label="{ Rack 1 Switch 1 | { <p1> P1 | <p1> P1 | <p3> P3} }", shape=record] } r1pf1:p1 -> switch1:p1 (obviously there are dozens of entries omitted here) Problem is: I have a hard time to influence graphviz to generate a bearable layout. Edges overlap so bad that you can't read the diagram anymore. The question is: What other tools (be it interactive like Visio, Omnigraffle or I/O-oriented like graphviz) exist that would allow an easily versionable (as in: Operates on a text file) documentation that is both machine and human readable and editable? Why not OmniGraffle or Visio? Well we don't have Macs and Visio is not available at the moment. To buy it I would need good arguments. Automation would be one of that. But last time I looked, versioning Visio files or even thinking about automatic handling was a nightmare. Related: Network Mapping Tools basically asks the same with a focus on generating the complete graph automatically (but without the need to document cabling connections) Recommendations for automatic computer inventory brings up links of "all-in-one" solutions

    Read the article

  • Cant insert row with auto-increment key via FluentNhibernate

    - by Jeff Shattock
    I'm getting started with Fluent NHibernate, and NHibernate in general. I'm trying to do something that I feel is pretty basic, but I cant quite get it to work. I'm trying to add a new entry to a simple table. Here's the Entity class. public class Product { public Product() { id = 0; } public virtual int id {get; set;} public virtual string description { get; set; } } Here's its mapping. public class ProductMap : ClassMap<Product> { public ProductMap() { Id(p => p.id).GeneratedBy.Identity().UnsavedValue(0); Map(p => p.description); } } I've tried that with and without the additional calls after Id(). And the insert code: var p = new Product() { description = "Apples" }; using (var s = _sf.CreateSession()) { s.Save(new_product); s.Flush(); } where _sf is a properly configured SessionSource. When I execute this code, I get: NHibernate.AssertionFailure : null identifier, which makes sense based on the SQL that NHibernate is executing: INSERT INTO "Product" (description) VALUES (@p0);@p0 = 'Apples' It doesnt seem to be trying to set the Id field, which seems ok (on its face) since the DB should generate that. But its not, I think. The DB schema is autogenerated by FNH: var config = Fluently.Configure().Database(MsSqlCeConfiguration.Standard.ShowSql().ConnectionString(@"Data Source=Database1.sdf")); var SessionSource = new SessionSource(config.BuildConfiguration().Properties, new ModelMappings()); var Session = SessionSource.CreateSession(); SessionSource.BuildSchema(Session); CreateInitialData(Session); Session.Flush(); Session.Clear(); I'm sure to be doing tons of things wrong, but whats the one thats causing this error?

    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

  • ASP.NET MVC 1 and 2 on Mono 2.4 with Fluent NHibernate

    - by SztupY
    Hi! I'd like to create an application using ASP.NET MVC, that should run under mono 2.4 (compiling will be done on a Windows box). Has anyone getting luck with this? Here is what I've already tried: ASP.NET MVC on mono without any persistence model support, and using nhaml as the view engine S#aml architecture, which is a quite good framework imho, but it depends too much on stuff, that are not working good under mono (like windsor) The first part worked fine, I didn't encounter any major problems. But I couldn't get the second part working. It seems it's dependency on Castle.Windsor breaks the whole mono support (but there might be other parts too). Therefore I decided to create an alternative framework, that borrows some of the ideas of s#arp-architecture, but designed to be working under mono (and if I'm able to do this I'll release it for the community of course). The controller and view part is working fine (not much magic here though, they have been always working), but I have some questions before I start job on the persistence part: What NHibernate versions are working under mono? I've heard 1.2 is working fine. Does 2.0.1/2.1 beta work under mono? Does Fluent.NHibernate and NHibernate.Linq work under mono? (for the latter it seems it needs some dependcies that aren't avaialable in mono) Are there any good alternatives for persistence support to NHibernate under mono? Alternative questions: Are there any frameworks that have mono+persistence+asp.net mvc support already or am I the first one to think about this? If you have already done this: what are your opinions on stability/usability? Thanks for the answers EDIT: Updated the framework to support ASP.NET MVC 2: http://shaml.sztupy.hu/

    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

  • NHibernate, legacy database, foreign keys that aren't

    - by Joe
    The project I'm working on has a legacy database with lots of information in it that's used to alter application behavior. Basically I'm stuck with something that I have to be super careful about changing. Onto my problem. In this database is a table and in this table is a column. This column contains integers and most of the pre-existing data have a value of zero for this column. The problem is that this column is in fact a foreign key reference to another entity, it was just never defined as such in the database schema. Now in my new code I defined my Fluent-NHibernate mapping to treat this column as a Reference so that I don't have to deal with entity id's directly in my code. This works fine until I come across an entity that has a value of 0 in this column. NHibernate thinks that a value of 0 is a valid reference. When my code tries to use that referenced object I get an ObjectNotFoundException as obviously there is no object in my database with an id of 0. How can I, either through mapping or some kind of convention (I'm using Fluent-nhibernate), get NHibernate to treat id's that are 0 the same as if it was NULL?

    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

  • Mapping tables from an existing database to an object -- is Hibernate suited?

    - by Bernhard V
    Hello! I've got some tables in an existing database and I want to map them to a Java object. Actually it's one table that contains the main information an some other tables that reference to such a table entry with a foreign key. I don't want to store objects in the database, I only want to read from it. The program should not be allowed to apply any changes to the underlying database. Currently I read from the database with 5 JDBC sql queries and set the results then on an object. I'm now looking for a less code intensive way. Another goal is the learning aspect. Is Hibernate suitable for this task, or is there another ORM framework that better fits my requirement?

    Read the article

  • How to save a large nhibernate collection without causing OutOfMemoryException

    - by Michael Hedgpeth
    How do I save a large collection with NHibernate which has elements that surpass the amount of memory allowed for the process? I am trying to save a Video object with nhibernate which has a large number of Screenshots (see below for code). Each Screenshot contains a byte[], so after nhibernate tries to save 10,000 or so records at once, an OutOfMemoryException is thrown. Normally I would try to break up the save and flush the session after every 500 or so records, but in this case, I need to save the collection because it automatically saves the SortOrder and VideoId for me (without the Screenshot having to know that it was a part of a Video). What is the best approach given my situation? Is there a way to break up this save without forcing the Screenshot to have knowledge of its parent Video? For your reference, here is the code from the simple sample I created: public class Video { public long Id { get; set; } public string Name { get; set; } public Video() { Screenshots = new ArrayList(); } public IList Screenshots { get; set; } } public class Screenshot { public long Id { get; set; } public byte[] Data { get; set; } } And mappings: <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SavingScreenshotsTrial" namespace="SavingScreenshotsTrial" default-access="property"> <class name="Screenshot" lazy="false"> <id name="Id" type="Int64"> <generator class="hilo"/> </id> <property name="Data" column="Data" type="BinaryBlob" length="2147483647" not-null="true" /> </class> </hibernate-mapping> <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SavingScreenshotsTrial" namespace="SavingScreenshotsTrial" > <class name="Video" lazy="false" table="Video" discriminator-value="0" abstract="true"> <id name="Id" type="Int64" access="property"> <generator class="hilo"/> </id> <property name="Name" /> <list name="Screenshots" cascade="all-delete-orphan" lazy="false"> <key column="VideoId" /> <index column="SortOrder" /> <one-to-many class="Screenshot" /> </list> </class> </hibernate-mapping> When I try to save a Video with 10000 screenshots, it throws an OutOfMemoryException. Here is the code I'm using: using (var session = CreateSession()) { Video video = new Video(); for (int i = 0; i < 10000; i++) { video.Screenshots.Add(new Screenshot() {Data = camera.TakeScreenshot(resolution)}); } session.SaveOrUpdate(video); }

    Read the article

  • NHibernate child deletion problem.

    - by JMSA
    Suppose, I have saved some permissions in the database by using this code: RoleRepository roleRep = new RoleRepository(); Role role = new Role(); role.PermissionItems = Permission.GetList(); roleRep .SaveOrUpdate(role); Now, I need this code to delete the PermissionItem(s) associated with a Role when role.PermissionItems == null. Here is the code: RoleRepository roleRep = new RoleRepository(); Role role = roleRep.Get(roleId); role.PermissionItems = null; roleRep .SaveOrUpdate(role); But this is not happening. What should be the correct way to cope with this situation? What/how should I change, hbm-file or persistance code? Role.cs public class Role { public virtual string RoleName { get; set; } public virtual bool IsActive { get; set; } public virtual IList<Permission> PermissionItems { get; set; } } Role.hbm.xml <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="POCO" namespace="POCO"> <class name="Role" table="Role"> <id name="ID" column="ID"> <generator class="native" /> </id> <property name="RoleName" column="RoleName" /> <property name="IsActive" column="IsActive" type="System.Boolean" /> <bag name="PermissionItems" table="Permission" cascade="all" inverse="true"> <key column="RoleID"/> <one-to-many class="Permission" /> </bag> </class> </hibernate-mapping> Permission.cs public class Permission { public virtual string MenuItemKey { get; set; } public virtual int RoleID { get; set; } public virtual Role Role { get; set; } } Permission.hbm.xml <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="POCO" namespace="POCO"> <class name="Permission" table="Permission"> <id name="ID" column="ID"> <generator class="native"/> </id> <property name="MenuItemKey" column="MenuItemKey" /> <property name="RoleID" column="RoleID" /> <many-to-one name="Role" column="RoleID" not-null="true" cascade="all"> </many-to-one> </class> </hibernate-mapping>

    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

  • MVC nhibernate entiry mapping for dropdown list

    - by Rod McLeay
    Hi, I have a dropdown list on an ASP.NET MVC project that I am pretty sure is not binding to my model because of my nhibernate mapping. I have tried many variations on the asp mvc side resulting in this post here. MVC side of things seems fine I believe the issue may be that my object is trying to bind, but my mapping is out of whack. My mapping is: <many-to-one name="Project" lazy="false" class="AgileThought.ERP.Domain.Property.Project" column="ProjectGUID" /> My View gives an error saying that the GUID from the dropdownList selected value is not valid. Which I think may be that it is trying to push the GUID into my related project object. The value 'fd38c877-706f-431d-b624-1269184eeeb5' is invalid. My related project list binds to the dropdown list just fine, it is just not binding to my models Project entity. Does the related Project entity need to know about its relationship? Its really just a lookup list. Many thanks for your time and best regards, Rod

    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

  • NHibernate Linq queries not returning data saved in the same transaction

    - by Andrew
    Hi, I have a situation where I am using NHibernate in a WCF service and using a TransactionScope for the transaction management. NHibernate enlists in the ambient transaction fine, but, any changes I make and save inside the transaction, are not visible to any queries I make while still in that transaction. So if I add an entity and session.save() it, then further on in the code, there is a linq query against that entities table, the entity I just added is not returned. Strangely this seems to work fine if I use explicit NHibernate transactions in my tests. Anyone have any ideas as to why and what I can do about it? Many thanks Andrew

    Read the article

  • Loading tables dynamically with NHibernate

    - by Trevor Goertzen
    I'm working on a project that requires me to load tables based on table names stored in another table. More tables will be added to the DB (and by someone else), so creating NHibernate mapping files for each table isn't an option. Does anyone know if it is possible to load tables dynamically using NHibernate? Edit: I should add that I'm on .NET 2.0, so I can't use Fluent NHibernate. Thanks for the suggestion though guys. I will use that as evidence in convincing my associates to upgrade.

    Read the article

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