Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

nHibernate Session.Query returns 0

$
0
0

Hello frnds,

I am tring to get all records of table in List . Using NHibernate and Linq . I am not getting any run time error or compile time error . But Result count in List is 0 . Here is my code - 

My App.Config File

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">Server=Localhost;Database=IPLTeams;Integrated Security=SSPI</property>
      <property name="show_sql">true</property>
      <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
      <property name="command_timeout">180</property>
      <!--<property name="connection.isolation">ReadCommitted</property>-->
      <mapping assembly="NHibernate_ConsoleApp"/>
    </session-factory>
  </hibernate-configuration>
</configuration>

Mapping Property Class

namespace NHibernate_ConsoleApp
{
    public class Teams
    {
        public virtual Guid TeamId { get; set; }
        public virtual string Teams1 { get; set; }
        public virtual int Id{get;set;}
        public virtual int Count { get; set; }
        public virtual bool IsActive { get; set; }
        public virtual bool IsDeleted { get; set; }
        public virtual DateTime CreatedDate { get; set; }
        public virtual DateTime UpdatedDate { get; set; }
    }
}

hbm file for mapping Database table with class

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernate_ConsoleApp" assembly="NHibernate_ConsoleApp"
                  >
  <class name="NHibernate_ConsoleApp.Teams,NHibernate_ConsoleApp" table="tblTeams">
    <id name="TeamId" type="Guid">
      <generator class="guid"/>
    </id>
    <property type="string" name="Teams1" >
      <column name="Teams"></column>
    </property>
    <property type="int" name="Id" column="Id"></property>
    <property type="int" name="Count" column="Count"></property>
    <property name="IsActive" column="IsActive"></property>
    <property name="IsDeleted" column="IsDeleted"></property>
    <property name="CreatedDate" column="CreatedDate"></property>
    <property name="UpdatedDate" column="ModifiedDate"></property>
  </class>

</hibernate-mapping>

And Finally Code for Select All Records from Table

 ISession objSession = SessionManager.OpenSession(); 
IList<Teams> mylist = objSession.Query<Teams>().ToList<Teams>();

My Session is successfully open and i am not getting any exception here. but in mylist , Count is 0.

Thanks & Regards

Shwetamber




Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>