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 QueryOver Class And Projection....

Introduction The ICriteria API is NHibernate's implementation of Query Object . NHibernate 3.0 introduces the QueryOver api, which combines the use of Extension Methods and Lambda Expressions (both new in .Net 3.5) to provide a statically typesafe wrapper round the ICriteria API. QueryOver uses Lambda Expressions to provide some extra syntax to remove the 'magic strings' from your ICriteria queries. So, for example: .Add(Expression.Eq("Name", "Smith")) becomes: .Where<Person>(p => p.Name == "Smith") With this kind of syntax there are no 'magic strings', and refactoring tools like 'Find All References', and 'Refactor->Rename' work perfectly. Note: QueryOver is intended to remove the references to 'magic strings' from the ICriteria API while maintaining it's opaqueness. It is not a LINQ provider; NHibernate 3.0 has a built-in ...

Understanding machine learning

What is machine learning does?  It Finds patterns in data and uses those patterns to predict the future.          EXAMPLES :  Detecting credit card fraud : You can use machine learning  detect credit card fraud, Suppose you have data about previous credit card transactions. You could find patterns in that data potentially  that allows you to detect when a new credit card transaction is likely to be fraudulent. Determining whether a customer is likely to switch to a competitor :  You could possibly find the patterns in the existing customer data that will help you do that Lots more What does it mean to learn ? Yes it's something like your own learning process. You have learned reading,listening, walking everything by using your experience on it, the data you have in your mind and continuous improvements.  How did you learn to read? Well learning requires identifying patterns. Reading for instance you ...

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.