Best Way To Use NHibernate With The Repository Model

Mar 16, 2009

I have a repository class that defines some basic Get/Save/Delete methods. Inside these, I use NHibernate to do the work on my business entities. For example:

[code]...

However, on my User class I have some properties and collections of other objects that ideally I'd like to be lazy loaded. But of course, the ISession is created and disposed within the repository, which I guess is why, outside of that, when I try to access those properties I get a "Could not initialize proxy - no Session" error.Is my only option then to disable lazy loading when using repositories? Or is it possible (or just foolish) to somehow get the session into scope in the business layer?I do like the repository model, and NHibernate is growing on me (after lots of initial frustration trying to make it work), so what's the best way you gurus have found of using them together?

View 1 Replies


ADVERTISEMENT

.net - NHIbernate NHibernate Attempts To Execute A Database Update During CreateQuery Execution?

Mar 10, 2010

Basically, I wish to fetch a filtered set of objects from the database (Oracle 9.2) based on the id property of the object PsalertsEvent. The code being executed is:

Public Overloads Function GetAll(ByVal laterThan As Long, ByVal filteredPsalertsEvents As IList) As IList Implements IPsalertsEventRepo.GetAll
'Get all psalerts events with an ID greater then the specified laterThan parameter
filteredPsalertsEvents = MyBase.NHibernateSession.CreateQuery("from PsalertsEvent p where p.id > " & laterThan).List

[Code]...

View 2 Replies

MS Entity Framework VS NHibernate And Its Derived Contribs (FluentNHibernate, Linq For NHibernate)?

Feb 4, 2010

I just read this article about the Entity Framework 4 (actually version 2).Entity Framework seems to offer a huge improvement over its first release. Thus, I have never ever used EF in any project, since I think EF is not mature enough in comparison to NHibernate.NHibernate and its current contributions of FluentNHibernate and Linq for NHibernate by Ayende RahienMy feeling is that Microsoft is solely trying to gain terrain it has lost in favor of NHibernate when the 2nd version of NHibernate came out.Nevertheless, my concerns are the followings (not in particular order):Will EF4 tend to be less XML-verbose?Will EF4 be compatible with other underlying datastore than just SQL Server?What are the greatest benefits of going with EF4 instead of FluentNHibernate or NHibernate itself.

NHibernate is a great tool, I guess everyone agrees. Due to its predecessor Hibernate, we may easily find documentions and tutorials and sample applications to get acquainted with it. This is not the case for FluentNHibernate. Particularly as per the project I'm working on right now which demands that I investigate further about NHibernate and its options (FluentNHibernate for instance) in order to document the rules of usage and the best practices of NHibernat and FluentNHibernate technology. Thus, being handcuffed with VB.NET, being a C-Style developer, I can't find some syntax equivalencies in VB.NET for the examples provided, though I made I way so far

View 3 Replies

VS 2008 .NET For NHibernate And Fluent NHibernate?

Oct 26, 2010

I would like to ask if you can use VB.NET for NHibernate and Fluent Nhibernate?I have searched the web, but I can't seem to get a detailed or explicit statement that tells that one can use VB.NET for NHibernate and with Fluent.

Many of the samples in the NHibernate site are made in C#. That's why I was wondering if I can't use VB.NET when using NHibernate.

View 2 Replies

Mvc - Using The Repository Pattern

Feb 23, 2011

I am using the Entity Framework with POCO's generated using the T4 Templates. I have the generated classes in a separate assembly. Ok, so a very simple example: I have a Category entity in the model which has SubCategories (1-Many with SubCategory). When I use the following code, I get The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. [Code]

View 2 Replies

Repository - .net Code Repositories Around?

Aug 1, 2010

I was wondering if there are any good vb.net code repositories around where people share code they have written, widgets they have developed, classes developed? I hate re-inventing the wheel.

View 3 Replies

.net - VS 2010 Entity Repository Error

Jun 12, 2010

In my project I have it set up so that all the tables in the DB has the property "id" and then I have the entity objects inherit from the EntityBase class using a repository pattern. I then set the inheritance modifier for "id" property in the dbml file o/r designer to "overrides"

Public MustInherit Class EntityBase
MustOverride Property id() As Integer
End Class
Public MustInherit Class RepositoryBase(Of T As EntityBase)

[Code]...

however produces the error "Class member EntityBase.id is unmapped" when i use VS 2010 using the 4.0 framework but I never received that error with the old one.

View 1 Replies

LINQ To SQL: Fake Repository With Many-to-Many Relationships?

Aug 6, 2009

I have two tables, Clients and Administrators, which are linked in a many-to-many relationship by the table ClientAdministrators. In the real application this works fine and I can get a list of Administrators for my Client. My problem comes in trying to unit test the service class that is retrieving this from the repository. I have a FakeRepository class which implements my repository interface and I have several internal lists of objects for the service class to query against.

[Code]...

View 3 Replies

Repository Record - Dirty Columns Are Always Zero

May 29, 2009

SubSonic 2.2. I use the repository record pattern, with a table "appointment" with an appointmentId as auto-incrementing int. I am trying to update it, but when I do update the fields with something totally different, dirty columns are always zero, and I get an exception.

[Code]...

View 1 Replies

Using The BusinessObjects SDK To Interact With Objects In Its Repository?

Oct 27, 2009

The File Class has methods for sending/receiving (CopyTo and Overwrite) binary data to/from the File Repository Server (where files like Crystal Reports are stored), both of which have an overload that supports 'Binary data (safearray of VT_UI1)

View 1 Replies

Files/sub-dirs When Adding Items In A New Repository?

Mar 23, 2010

I didn't see a question on this subject in the archives, so here goes: For those of you experienced Mercurial users, is this a correct .hgignore file to tell VB.Net Express to ignore files/sub-dirs when adding items in a new repository?

[Code]...

View 1 Replies

Generic Repository With Entity Framework 4.0 Function Imports?

Feb 23, 2010

I have a generic repository that I communicate with my object context with. My object context has function imports that I want to be able to call through my generic repository. Currently I call them through an "Execute" function, but this is not ideal because I have to pass in my function name and parameters as strings which can cause run-time exceptions. My function imports map to complex types.

Is there a way to do something similar to:

Dim rep As IRepository(Of ComplexType)

Dim type As ComplexType = rep.Find(where:=Function(t) t.FunctionImport(parm, parm)).First()

Here is my generic repository as is:

[Code]...

View 1 Replies

Repository Is Nothing But Added In The Container Later (correctly) (using Unity, Repositories) In ASP.Net MVC 3?

Sep 1, 2011

I have a "MenuService", which uses an "MenuRepository".When the MenuService is created, it loads correctly with the MenuRepository.Then it wants to save it in the UnityControllerFactory, but the MenuRepository in the MenuService is Nothing then (it wasn't before).Some additional info:I'm using the Unity and Repository pattern.The problem happens with a partial view (for a menu), which i have included in the "HomeController", it could be relevant information, so i included this, just in case:

Function Menu() As ActionResult
Return PartialView("~Views/Shared/_Menu.vbhtml", _MenuService.GetAllMenuItems)
End Function

Also, my partial "menu" view is like this:

~/_Menu.vbhtml
@ModelType IEnumerable(Of FacturatieMVCv2.Domain.Slave.MenuItem)
@*<div id="myslidemenu" class="jqueryslidemenu">*@

[code]....

And i'm calling the partial view with:

@Html.Action("Menu","Home")

View 1 Replies

.net - Repository Pattern - Remove Child Elements From Multiple Parents

Nov 16, 2011

I have the following tables

Public Class Tag
<Key()> _
Public Property TagID As Integer

[Code].....

I implemented the repository pattern.

Now i have a list of Tags which contain the right TagReferences, but the tags may not be deleted, it's the TagReferences.

Variabels = ReferenceValue,ReferenceID
IEnumerable(Of Tag) = TagRepository.GetMany(Function(el) el.Reference = ReferenceValue And el.TagReferences.Any(Function(bl) bl.ReferencedID.Equals(ReferenceID)))

How can i remove all the TagReferences which contain the ReferenceID in one line?

View 1 Replies

Svn - TortoiseSVN Hangs With .vbproj File On Initial Import To Repository?

Aug 25, 2011

we have a CollabNet Subversion Edge server running on a Windows server. Subversion Server is configured to serve via https. When trying to import a Visual Studio project folder with TortoiseSVN it hangs when adding the project file (.vbproj). Test 1: It happens exactly the same when the server is configured to serve via http.Test 2: Importing any project folder using the console utility (svn) works fine.

Both these tests lead to the conclusion that there is neither a network nor authorization problem.

View 1 Replies

How To Use QueryOver With NHibernate

Feb 7, 2012

how to use nHibernate with Vb.net using all the examples online(which are in C#) to learn. Which has been fine for the basics, but now I'm trying to learn how to use QueryOver's JoinAlias, and going from C# to VB.net is difficult. I've been using this page's answer as a reference, but I'm still having trouble converting an example like that to Vb.net.

View 1 Replies

.net - Can't Get Linq To NHibernate To Work?

Nov 22, 2009

I'm struggling with getting Linq To NHibernate to work.I have referenced NHibernate, NHibernate.Linq and NHibernate.ByteCode.Castle . Also I have all other dependencies in the same folder.

Code / Error message:

Public Function GetProjectsByName(ByVal ProjectName As String) As List(Of Project)
Return (From x In _session.Linq(Of Project)() Where x.Name.Equals(Project))

End Function[code]....

... tells me that the LINQ extensions aren't loaded. Using NHibernate.Linq seems to be made in a way that it's incredibly easy to use, hence there are no tutorials on how to set it up. (Or at least I couldn't find any).

View 1 Replies

NHibernate HQL Dynamic Instantiation?

Jun 27, 2012

I can't find what's going on with the following nHibernate HQL.

here's my VB.Net code:
Return _Session.GetNamedQuery("PersonAnthroSummary").SetInt32(0, 2).UniqueResult()
My Named Query:

[code].....

View 2 Replies

NHibernate Select Query?

Mar 16, 2009

I have an ado.net statement I want to convert to use NHibernate:

Dim sql As New StringBuilder()
sql.AppendLine("SELECT r.RoleId, r.RoleName ")
sql.AppendLine("FROM dbo.aspnet_Roles r ")

[code]...

View 1 Replies

.net - Fluent NHibernate Duplicate Columns?

Dec 28, 2011

I am having some redundant primary key issues.I have an Item which contains many reports. I have mapped them as shown below. I can do Session.QueryOver(Of Item).List and there are no extra columns generated. I can also do Session.QueryOver(Of Report).List and there are no extra columns generated.

However, once I try to traverse the relationship from Item to Reports, I get the SQL query shown below. Can anyone tell me why?

[Code]...

View 2 Replies

C# - Executing Sql Statements With Fluent NHibernate

May 12, 2009

Basically I want to be able to do this:

session.ExecuteSql("...");

I don't need it to map to any entities or return any values.

View 1 Replies

C# - NHibernate Entity Code Conversion From #C?

Jan 12, 2011

I am starting on the NHibernate world and i am experimenting with the NHibernate CookBook
recipes, i am trying to set a base entity class for my entities and this is the C# code for this. I would like to know whats the VB.NET version so i can implement it in my sample project

View 3 Replies

Error Building SessionFactory In NHibernate?

Apr 28, 2009

I am getting an "ArgumentOutOfRangeException" on parameter index whenever I try to instantiate a session factory in nHibernate. The error comes from a procedure deep in the bowels of nHibernate. This is on a fresh project with a pretty simple three tier architecture. The data layer maps the nHibernate classes to simple interfaces which are implemented by the business layer.Currently there is only one interface set and mapping file being used by nHibernate. Hopefully my issue is easy to spot.

Here is the function where I build the sessionFactory.

Private Shared Function SessionFactory() As ISessionFactory
If _sessionFactory Is Nothing Then
Dim config As New NHibernate.Cfg.Configuration
config.Configure()

[code]....

Edit2: When I remove the discriminator I no longer get this error. Am I not doing that right?

Edit 3: When I download the source code for nHibernate, build it on my own, link to it's debug output and run it, I get a completely different error about ProxyFactoryFactory not being configured.

View 1 Replies

Ignoring Properties In Fluent NHibernate With (2.0)?

Jul 29, 2010

Because there is so little information about VB.Net and (Fluent) NHibernate to be found, I decided to write this question to all other developers finding themselves looking for more information.On of the things i had to struggle with was how to Ignore properties in NHibernate.The reason i had to ignore properties was because we used a Webserivce which cannot serialize Interface classes (ILists). Which are used a lot with NHibernate.

View 1 Replies

NHibernate & SQLite = [Class] Is Not Mapped?

Dec 21, 2010

Well i have been fighting with this for a little bit now, and i can't seem to find a solution for something it should be really simple. I got a class ( really simple class ) i got the hbm.xml ( SET AS EMBEDDED RESOURCE ) i got the config file set for SQLite but i still get the [Class] Is not mapped.Here is where the error comes up, when i run this:

Public Sub LoadCentersFromDatabase()
Try
Dim session As ISession = OpenSession()
Dim query As IQuery = session.CreateQuery("from Center")

[code]....

View 1 Replies

Options Are Available For A Developer When Using Fluent NHibernate?

Jul 9, 2010

I've been using c# for the past year and I enjoy the power you get with Fluent NHibernate. One question that I get from friends is "nice but how can vb.net programmers use this?"So for example- the below is a c# mapping class. How would someone do this with vb.net?

public class PostMap : ClassMap<post>
{
public PostMap()
{
Table("Posts");

[Code]...

View 1 Replies

Binding NHibernate Proxy Objects To A DataGridView?

Jan 22, 2012

I am attempting to bind objects pulled from an NHibernate session to a DataGridView and am having problems.I have a single session in which I fetch all of my "look-up" items that are bound to a combobox column, and then I query for the objects themselves. omehow, this still results in proxy child objects on the main objects. I have even changed the mapping of the look-up items to eager fetch, but I still get proxies somehow.Here is how I am fetching the objects:

Dim _makes As IList(Of Make) = session.QueryOver(Of Make).List
Dim _models As IList(Of Model) = session.QueryOver(Of Model).List
Dim _cars as IList(of Car) = session.QueryOver(of Car).List

[code].....

View 1 Replies

C# - Nhibernate Mapping Of System.Drawing.Image?

Oct 5, 2010

Question: I get an exception serializing this class to a nHibernate xml file ({"Could not determine type for: System.Drawing.Image, System.Drawing, for columns:NHibernate.Mapping.Column(Settings)"}).

using System;
using System.Collections.Generic;
using System.Text;

[code].....

View 3 Replies

How To Persist Anonymous Types Instances Through NHibernate

Feb 12, 2010

Instinctively, I would say that this is impossible, as NHibernate needs to know some mapping information on how to persist a given type. Thus, I encountered some situations in which I could use such a feature. For instance, through a named query or something like so. On the other hand, using a named query would require me to make an addition to the configuration file.

Let's suppose we have an application interacting with some underlying datastore. This datastore is configured through the NHibernate configuration file. Then, I wish to have NHibernate load only a subset of an entity properties, from another subsystem to which my application shouldn't need to interact much, so it is not worthy to define classes for this system, as I only need a fraction of this alien system's information, let's say three out of thirty-two data columns. For that matter, if I chose to load only those three columns let's say for performance concerns, I would then use an anonymous type, perform the required action onto this information, then persist it back to the datastore. Now, it wouldn't be of much interest to do so if I only had one entity to get loaded from the datastore, so let's say I have about 75,000 rows to load into my process. I then shall consider this subset option very seriously!

What strategy should you choose in such situation, if you needed to persist these changes to a subset only of this entity's properties?FYI: I am asking because I must write specific rules of usage with NHibernate, such rules that even a beginner developer would even be able to use it without knowing too much about NHibernate, but only following the rules and guidance of the technical documents I have to produce.

View 1 Replies

Mapping Custom GUID With Fluent NHibernate

Dec 6, 2011

I am using Fluent NHibernate to map an Oracle database. It is a legacy database so I cant really change everything I want.There is a GUID field, but the keys are still composite (I will change this as soon as I can so that the keys are not composite, but I cant do it right now). The GUID is a VARCHAR2 field with this layout: 551608b1-275d-49f6-9561-44d01aacf23f. The GUID is not added by a sequence in Oracle, but inserted from code (C# or VB.net)[code]Is the problem that I dont use a sequence to generate my GUID? How can I overcome this?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved