Skip to main content

Sample code for Populating DropDownList Using QueryOver In NH3

  
Code For Populating DropDownList 
 
 NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
            Assembly myAssenbly = typeof(Contactss).Assembly;

 config.AddAssembly(myAssenbly);
                ISessionFactory factory = config.BuildSessionFactory();
                ISession session = factory.OpenSession();
                IList FName =(IList)session.QueryOver<Contactss>().Select(c => c.FirstName, c => c.ContactId ).List<object[]>().Select(x => new {
                fn=(string)x[0],
                Id=(Int32)x[1]
                }).ToList();
                DropDownList1.DataSource = FName;
                DropDownList1.DataTextField = "fn";
                DropDownList1.DataValueField = "Id";

                DropDownList1.DataBind();
                session.Close();



contactss is a Business Model as follows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1
{
    public class Contactss
    {
        private int _contactId;
        private string _firstName;
        private string _lastName;
        private string _email;
        private string _telephone;

        public virtual int ContactId
        {
            get { return _contactId; }
            set { _contactId = value; }
        }

        public virtual string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        public virtual string LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }

        public virtual string Email
        {
            get { return _email; }
            set { _email = value; }
        }

        public virtual string Telephone
        {
            get { return _telephone; }
            set { _telephone = value; }
        }

     
    }
}

Comments

Popular posts from this blog

NHibernate Introduction

 NHibernate NHibernate is an open source Object-Relational Mapping (ORM) tool for the .Net platform… and the existing documentation and tutorials that I could find, whilst plentiful, are not aimed at those new to or inexperienced with ORM. This tutorial is based on using Visual Studio (I used 2008 beta 2) and Sql Server, however the database used is almost immaterial (one of the advantages of using an OR mapper). If you already know what NHibernate and ORM are and you want to use it but just need to know how?  Otherwise, read on. WTF is ORM? There is plenty of good stuff out there on what Object-Relational Mapping is, try wikipedia or the intro here (the tutorial is a bit out of date but the explanation is good) or there’s always Google . However, in a nutshell, ORM is the process of mapping business objects (think OOP) to database relations (read tables). An OR Mapper is a tool that manages this process. There are several different OR Mappers available for ...

Computer Science Defenition

Computer Science Computer science is the scientific and practical approach to computation and its applications. It is the systematic study of the feasibility, structure, expression, and mechanization of the methodical procedures (or algorithms ) that underlie the acquisition, representation, processing, storage, communication of, and access to information , whether such information is encoded as bits in a computer memory or transcribed in genes and protein structures in a biological cell . [1] A computer scientist specializes in the theory of computation and the design of computational system

Machine learning in a Nutshell

you start with the data that contains patterns. you can feed that data to the machine learning algorithm (may be more algorithms) to find the patterns in the data .This algorithm generates something called a model.Model functionality is to recognizes the patterns then presented with the new data. Application supplies new data to see if it matches known patterns such as the data about new transactions. The model can determine the probability whether the transaction is fraudulent or not, it knows that because of the patterns.      Machine learning lets us find patterns in existing data, then create and use a model that recognizes those patterns in new data Machine learning has gone mainstream - big vendors think there's big money in this market      Machine learning can probably help your organization.