473,511 Members | 14,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with ICriteria interface within NHibernate (C#)

57 New Member
Hi, I'm pretty new to the NHibernate framework and am trying to use it to query my database. I have a lookup table set up (image.hbm.xml) with the properties set out as follows:

Expand|Select|Wrap|Line Numbers
  1.     <property name="ForeignLink" column="FORNBLG" />
  2.     <property name="IncludeInMerge" column="INCLUDE_IN_MERGE" />
  3.     <property name="ReferenceNumber" column="REF_NO" type="AnsiString"/>
  4.     <property name="FileName" column="FILENAME" type="AnsiString"/>
  5.     <property name="Notes" column="NOTES" type="AnsiString"/>
I then also have a class set up representing the lookup table (image.cs), and the name of the table in the database is IMAGE.

OK, now what I am doing is passing a string into a web service for example "2523-ATTACHMENT-57925", and the web service parses the number at the end of this string as an Integer which represents the primary key of the IMAGE table (field name LINK). I need to use this primary key as my search criteria and return the value from the field NOTES and return it as a string.

I have the following code set up and am not too sure how to continue with it to return the string..

Expand|Select|Wrap|Line Numbers
  1. using (ISession session = mSessionFactory.OpenSession())
  2.                     {
  3.                         try
  4.                         {
  5.                             if (myString.IndexOf("-ATTACHMENT-") >= 0)
  6.                             {
  7.                                 //get primary key from myString (number after -ATTACHMENT-)
  8.                                 int pk = int.Parse(myString.Substring((myString.IndexOf("-ATTACHMENT-") + 12)));
  9.  
  10.                                 ICriteria criteria = session.CreateCriteria(typeof(Image));
  11.                                 criteria.Add(new EqExpression("Link", pk, true));
  12.                                 Image image = (Image)criteria.UniqueResult();
  13.                                return ..............
  14.  
  15. etc...
  16.                             }
Apr 3 '09 #1
2 3169
moorcroft
57 New Member
I've just realised it's easier than I thought, simply now have to say:

Expand|Select|Wrap|Line Numbers
  1. return image.Notes
:D
Apr 3 '09 #2
Frinavale
9,735 Recognized Expert Moderator Expert
I'm glad that you were able to solve your problem.
Thanks for sharing your solution, it'll probably help others facing the same problem :)

Just a note though: NHibernate is not native to the .NET environment. It is free as open source software that is mainly used to map .NET classes to database tables (from what I understand).

Because it's not part of the .NET Framework (it's open source software developed a third party), you will probably not be able to find help for it here in the .NET forum....unless you're lucky and another member has used it before.

-Frinny
Apr 3 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
1653
by: anna | last post by:
Map, generate, and maintain 50% of your .NET application code, namely your business and data objects. Use these objects in ASP.NET, Windows Forms, console or services applications. Business and...
2
2887
by: rajivpopat | last post by:
I've been reading a discussion thread at http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_frm/thread/119f8362a9f5ff52 regarding typecasting generic collections to...
0
3306
by: Pierre | last post by:
Hi, In my C# project (VisitorManagement) I have a subfolder (BusinessObjects) in which I have put the objects needed for NHibernate and the mapping files. In the top of my web service I do a...
8
8448
by: Roman | last post by:
Hello i got this simple problem using nhibernate. I want to chang the id( primary key of the) object and update it, to change this key. i me getting nhibernate exception like this: identifier...
1
13692
by: erin.sebastian | last post by:
Hello All, I am new to hibernate and new to nHibernate. I created a small app and when i try and run it i get the error i posted at the bottom of this message. I am using the helper class that...
0
3451
by: Pieter | last post by:
Hi, I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from BindingList(Of T) ) for all my lists. The NHibernate documentation told me that I had to implement...
4
3320
by: IceMan | last post by:
Hi, I am using the configuration object and passing it a Assembly object to load. The assembly object i pass in is from a dll which is in a different folder then the Nhibernate dll. The...
14
3657
by: thj | last post by:
Hi, I was wondering what you guys are using and why? LINQ to SQL or NHibernate? Thanks in advance, Tommy
1
2241
by: moorcroft | last post by:
Hi I'm looking for help with getting the latest NHibernate to work with my .Net 3.5 VS 2008 project that I am migrating from .Net 2.0 on VS 2005. Previously (VS 2005 .Net 2.0) I would use the folling...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.