title: Fluent Nhibernate Mapping for Sql Views
body: <p>i am using Fluent Nhibernate in asp.net mvc3 with c# </p>
  
  <p>i am working in following way to generate and map a class </p>
  
  <p><strong>Mapping</strong></p>
  
  <pre><code>using FluentNHibernate.Mapping;
  using Com.Web.Domain;
  
     namespace Com.Web.Mapping
        {
           public class CompanyMap : ClassMap&lt;Company&gt;
          {
               public CompanyMap()
              {
                 Id(x =&gt; x.id);
                 Map(x =&gt; x.Name);
                }
            }
         }
  </code></pre>
  
  <p><strong>Class</strong></p>
  
  <pre><code>     using System.Collections.Generic;
       using System;
  
        namespace Com.Web.Domain
        {
  
            public class Company
           {
  
            public virtual int id { get; set; }
            public virtual string Name{get;set}
  
             }
  
          }
  </code></pre>
  
  <p>and in configuration file </p>
  
  <pre><code>  private static void InitializeSessionFactory()
      {
  
         _sessionFactory = Fluently.Configure()
              .Database(MsSqlConfiguration.MsSql2008
                            .ConnectionString(local)
  
              )
              .Mappings(m =&gt;
                        m.FluentMappings
                            .AddFromAssemblyOf&lt;Company&gt;())
              .ExposeConfiguration(cfg =&gt; new SchemaExport(cfg)
              .Create(false, false))  // this is intentionally set false , bcz i dont want to regenerate table when application starts every time 
              .BuildSessionFactory();
  
  
      }
  </code></pre>
  
  <p>now problem come i create a view in sql looks like this </p>
  
  <p><strong>Sql View</strong></p>
  
  <pre><code>CREATE VIEW [FeaturedCompanies] AS
  
     SELECT COUNT(Company.id) As Count FROM Company
     WHERE Name='Alias'
  </code></pre>
  
  <p>i want to use this view in my code as a like i am using but how can i do that , i searched alot but found nothing on google </p>
  
  <p>Pleas help me out and thanks in advance </p>
  
  <p><strong>what is tried so far</strong> </p>
  
  <p><strong>Class</strong></p>
  
  <pre><code>public class FeaturedCompany
  {
      public virtual int id { get; set; }
      public virtual int name { get; set; }
      public virtual int count { get; set; }
  }
  </code></pre>
  
  <p><strong>Mapping</strong></p>
  
  <pre><code>public class FeaturedCompanyMap : ClassMap&lt;FeaturedCompany&gt;
    {
   public FeaturedCompanyMap()
   {
      Table("FeaturedCompanies");
      ReadOnly();
     Id(x =&gt; x.id);
     Map(x =&gt; x.name);
     Map(x =&gt; x.count);
   }
  }
  </code></pre>