Hi,

var userM = session.CreateCriteria<User>("usr").List<User>();

I think you don't need this "usr"  in  CreatCriteria because you are not
using projections... (see:
http://nhibernate.info/doc/nhibernate-reference/querycriteria.html)

*"The Alias() and As() methods simply wrap a projection instance in
another, aliased, instance of IProjection."*




2016-05-08 23:12 GMT-03:00 Praveen Liyanaarachchi <
[email protected]>:

> Hello,
> I just trying to access data using *FluentNhibernate* / C# and i got
> following error message when i trying to execute a sql query. I would
> appreciate any help
>
> Exception: NHibernate.Exceptions.GenericADOException: Unable to perform
>> find[SQL: SQL not available] ---> System.ArgumentException: The value
>> "SampleProject.User" is not of type "SampleProject.User" and cannot be used
>> in this generic collection. Parameter name: value at
>> System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type
>> targetType) at
>> System.Collections.Generic.List`1.System.Collections.IList.Add(Object item)
>> at NHibernate.Util.ArrayHelper.AddAll(IList to, IList from)
>> at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
>> --- End of inner exception stack trace --- at
>> NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) at
>> NHibernate.Impl.CriteriaImpl.List(IList results) at
>> NHibernate.Impl.CriteriaImpl.ListT
>
>
>
> my scripts are looks like follows.Seems like something wrong with
> FluentMappings
>
> namespace SampleProject{public class NHibernateHelper{
>     public NHibernateHelper()
>     {
>         InitializeSessionFactory();
>     }
>     private static ISessionFactory m_SessionFactory;
>     public static ISessionFactory SessionFactory
>     {
>         get
>         {
>             if (m_SessionFactory == null)
>                 InitializeSessionFactory();
>             return m_SessionFactory;
>         }
>     }
>     private static void InitializeSessionFactory()
>     {
>         try
>         {
>             string connectionString = "";
>             connectionString = 
> "Server=localhost;Port=3306;Database=myDB;Uid=testUser;Pwd=123; Allow Zero 
> Datetime=true;Convert Zero Datetime=true; CharSet=utf8";
>             m_SessionFactory = Fluently.Configure().Database(
>             MySQLConfiguration.Standard
>             .ConnectionString(connectionString))
>             .Mappings(m => m.FluentMappings.AddFromAssemblyOf<GetData>())
>             .ExposeConfiguration(cfg => 
> cfg.SetProperty("connection.release_mode", "on_close"))
>             .BuildSessionFactory();
>         }
>         catch (FluentConfigurationException e)
>         {
>             throw e.InnerException;
>         }
>     }
>
>     public static ISession OpenSession()
>     {
>         return SessionFactory.OpenSession();
>     }
> }
> }
>
>
>
> public class User{
>     public virtual int UserID { get; set; }
>     public virtual string Name { get; set; }}
> public class UserMap : ClassMap<User>{
>     public UserMap()
>     {
>         Id(x => x.UserID ).Column("user_id");
>         Map(x => x.Name).Column("name");
>         Table("User_master");
>      }}
>
>
> // Execute sql query
>
> using (var session = NHibernateHelper.OpenSession()){
>       using (var transaction = session.BeginTransaction())
>       {
>           var userM = session.CreateCriteria<User>("usr").List<User>();
>
>
>       }}
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to