.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Imran Ghani
Post New Web Links

Projections using nHibernate

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net
 

I am using a simple Sum() projection and I can't get it to work.

I build my criteria in 2 steps.

I have a Sales Property in the "SalesAndQuota" class that have about 10 properties. I am trying to test with 1 field first then add the rest.

here's the simple code

            ProjectionList projectionList = Projections.ProjectionList();
            projectionList.Add(Projections.Sum("Sales"), "Sales");


I then call the SetProjections method

            if( projectionList != null )
            {
                query.SetProjection(projectionList);
            }


And this doesn't work.

 

Here's my error message.

The value "1008097.37" is not of type "SalesAndQuota" and cannot be used in this generic collection.
Parameter name: value

 It appears the code is trying to set sum to actual class name? AmI doing this completely wrong, because Sales is a field in the SalesAndQuota class.

 

Thanks,

Nick




View Complete Post


More Related Resource Links

Smart Client: Building Distributed Apps with NHibernate and Rhino Service Bus, Part 2

  

Smart client applications are responsive and promote interactivity with the user. In this article, we continue building a smart client application using NHibernate for data access and Rhino Service Bus for reliable communication with the server.

Oren Eini

MSDN Magazine August 2010


Smart Client: Building Distributed Apps with NHibernate and Rhino Service Bus

  

Smart client applications are responsive and promote interactivity with the user. In this article, we start the processes of planning and building a smart client application using NHibernate for data access and Rhino Service Bus for reliable communication with the server.

Oren Eini

MSDN Magazine July 2010


Data Access: Building a Desktop To-Do Application with NHibernate

  

Building an NHibernate-based desktop application isn't any harder than building a web application, and in many cases NHibernate simplifies elements of session handling and concurrency.

Oren Eini

MSDN Magazine December 2009


Cannot Insert records in table using NHibernate

  
I am very much new with NHibernate. I am inserting a new record in the table. However, it seems that it does not insert. What I'm using is Fluent NHibernate.Below is the code which inserts records. public virtual void Save(string CreatedBy) { ISession NHSession = Star.CNPL_BusinessObjects.Common.Session.OpenSession(); ITransaction NHTransaction = NHSession.BeginTransaction(); try { this.Save(CreatedBy, NHSession); NHTransaction.Commit(); NHSession.Flush(); } catch (Exception ex) { NHTransaction.Rollback(); throw ex; } } public virtual void Save(string CreatedBy, ISession Session) { try { if (this.IsPersisted) { this.SaveAuditTrail(Session, false, CreatedBy); Session.SaveOrUpdateCopy(this); } else { Session.Save(this); } } catch (Exception ex) { throw ex; } }

Examples for custom query using nhibernate in asp.net 3.5

  
I am doing a project in which i am using nhiberante ORM, In that they provide default method, but i req. more custom query like getting data by using join, to get particular column, So, i req. help from expert developers, plz help me. Thanks in advanced.

Cannot add record in table using NHibernate

  
Hi there!I'm new to NHibernate and I need help on this issue.No records where inserted in my SQL Table after committing the transaction or after the .Flush() method. I checked the code and it follows the correct sequence of codes. I can't seem to find any other way where the error fails.

Kindly guide me to get a quick start with latest NHibernate Technologies

  
I worked on NHibernate around 4 years ago, now in one of the project I want to implement it again. Can someone share their experiance about latest tools available to speedup the development of NHibernate.I have used a tool to generate ORM Mapping (I think its name was Puzzle.Net), can you also sugesst some good tools for NHibernate.

Example of quick and easy domain model that is persistable with NHibernate

  
am looking for the best approach to using NHibernate and MVC.net. I have gone through http://www.codeproject.com/KB/architecture/NHibernateArchitecture.aspx Someone has pointed to the use of Castle project Active record. My aim is to eliminate the need for any nhibernate dependencies within my domain. I want a quick and easy domain model that is persistable with NHibernate. Can I have a simple example and and some explanations please from which I can learn to use the castle project to build a simple application in MVC.net. Thanks am looking for the best approach to using NHibernate and MVC.net. I have gone through http://www.codeproject.com/KB/architecture/NHibernateArchitecture.aspx Someone has pointed to the use of Castle project Active record. My aim is to eliminate the need for any nhibernate dependencies within my domain. I want a quick and easy domain model that is persistable with NHibernate. Can I have a simple example and and some explanations please from which I can learn to use the castle project to build a simple application in MVC.net. Thanks

Cache data and Nhibernate

  
Hi all, I have use Nhibernate in my MVC Projectby me known, Nhibernate have cache on Session and Object.now, I want use HttpContext.Current.Cache (system.web) for cache data something in project.------------------------------------------------------my code same that have problem, haven't it. and that's right or wrong.Thanks you very much!

NHibernate with Pubs database

  
HI all, I have just started learning NH. As a practice i created one project & using pubs sample database (sql 2005). I used code generation tool, MyGeneration to generate entities/domain classes & mapping files (.hbm.xml). Till this point everything is fine. The problem is dbo.discounts table in pubs db does not have any Id field, so my Discounts.hbm.xml file looks as below: <?xml version="1.0" encoding="utf-8"?><hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">  <!--Build: with lujan99@usa.net Nhibernate template-->  <class name="Pubs.DAL.Domains.Discounts,Pubs.DAL" table="discounts" lazy="true">    <property name="Discounttype" column="discounttype" type="string" not-null="true" />    <many-to-one name="Stores" column="stor_id" cascade="save-update" />    <property name="Lowqty" column="lowqty" type="short" />    <property name="Highqty" column="highqty" type="short" />    <property name="Discount" column="discount" type="Decimal" not-null="true" />  </class></hibernate-ma

nhibernate +fluent +lazyload(?)

  

Hi all.


Tables:



Mapping:


public class ArticleMap : ClassMap<Article>
    {
        public ArticleMap()
        {
            Table(FieldNames.Article.Table);
            Id(x => x.ID).GeneratedBy.Native();
            Map(x => x.Author).Not.Nullable();
            Map(x => x.CreatedDate).Not.Nullable();
            Map(x => x.Content).Not.Nullable();
            References(x => x.Category).Not.Nullable().Column(FieldNames.Article.CategoryID);
            Map(x => x.Published).Not.Nullable();
            Map(x => x.Saved).Not.Nullable();
            Map(x => x.IsNews).Not.Nullable();
            
            HasManyToMany(x => x.Tags).Table("ArticleTags").ParentKeyColumn("ID").ChildKeyColumn("ArticleID");
        }
    }

public class TagMap : ClassMap<Tag>
    {
        public TagMap()
        {
            Table(FieldNames.Tag.Table);
            Id(x => x.Id);
            Map(x => x.Name).Not.Nullable();
            
            HasManyToMany(x => x.Articles).Table("ArticleTags")

How To Do Future Data Projections

  

We are looking at the best way to do data projections. Recalling my math classes, linear regression (least squares) lines come to mind. Though, is there a way to automatically choose the best model; ie; linear, logarithmic, exponential? What is the best way to do this in SQL 2008? Assume we have the following data:

Month            Profit
Jan                12.4
Feb                10.7
March             14.7
April               15.8
May                19.5
June               17.3

Then we want to project the next SIX months going forward. Thanks.


Switch (with Nhibernate )

  

Hey Everyone..
 i  need to  return the  Ilist corresponding to the cases.

 i have a problem in   switch.
1-    when   i m  Returning a  value , it  gives error  ("Not all paths  return a value")

and

2-    when i  put  return outside the  switch block  or outside the  case ,it gives  error ("the retval doesnt exist in the current

context")

please  help ..
      

 public object GetAll(object _oplObj)
        {
            using (NHibernate.ISession session = OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    ICriteria crit = session.CreateCriteria(_oplObj.GetType());
         &n

Server error regarding semaphores/NHibernate

  

Hello all.

 

Getting a previously unbeknownst server error regarding NHibernate and semaphores.  Seems errors have been accumulating and causing the semaphore timout period to expire occasionally.  The code which performs the execition and the resulting stack trace are provided.  Anybody have any ideas?

Thanks!

 

******code****************

LtExpression statusLessThanShipped = new LtBLOCKED EXPRESSION;

IList<Run> runs = RunProvider.CustomQuery(new Order[] {Order.Asc("RunNumber") } , new ICriterion[]  {statusLessThanShipped});

 

which in turn calls

public static new IList <Run> CustomQuery(Order[]  order, ICriterion[] criteria)

{

        return BaseProvider<Run>.CustomQuery(order, criteria);

}

 

********************************************

 

results in this stack trace*********************

 

 

Server Error in '/' Application.


Adding the given count to the semaphore would cause it to exceed its maximum count.

Description: An unhandled exception occurred during the execution of the current web request. Please review

Nhibernate Mapping exception

  

i  am getting  an error

Association references unmapped class: Jinnah.ObjectPersistanceLayer.Classes.TPF_Teacher_Performance

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.MappingException: Association references unmapped class: Jinnah.ObjectPersistanceLayer.Classes.TPF_Teacher_Performance

Source Error:

Line 21:                 c.Configure(this._configureFilePath);
Line 22:                 c.AddXmlFile(this._objectMappingPath);
Line 23:                 _factory = c.BuildSessionFactory();
Line 24:             }
Line 25:             return _factory.OpenSession();


Source File: C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\ERP-QA-Solution\Jinnah.NhibernateDAL\Data.cs    Line: 23

 

 

 

I  have checked all mapping files , and classes .

also  set  the Embeded resource   property of&n

Nhibernate (one-to-many relation with inverse="false" )

  

Hii all ..
can  somebody provide me  with the  example  tutorial of  <many-to-one>  mapping   ,where  inverse="false" (means  one way)

with the C#  coding  (for the aspx page )

 


want to knw how  to set  the foreign key field in the method

thanks  in advance


Select Query to get records within last 24 hours in Nhibernate

  

Hi All

How to Retrive records within last 24 hrs using Nhibernate.
I want to retrieve the 10 records within last 24 hours.

How can i achieve this using Nhibernate.

Please Help.



Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend