Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8639107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:54:57+00:00 2026-06-12T10:54:57+00:00

i am using Fluent Nhibernate in asp.net mvc3 with c# i am working in

  • 0

i am using Fluent Nhibernate in asp.net mvc3 with c#

i am working in following way to generate and map a class

Mapping

using FluentNHibernate.Mapping;
using Com.Web.Domain;

   namespace Com.Web.Mapping
      {
         public class CompanyMap : ClassMap<Company>
        {
             public CompanyMap()
            {
               Id(x => x.id);
               Map(x => x.Name);
              }
          }
       }

Class

     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}

           }

        }

and in configuration file

  private static void InitializeSessionFactory()
    {

       _sessionFactory = Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
                          .ConnectionString(local)

            )
            .Mappings(m =>
                      m.FluentMappings
                          .AddFromAssemblyOf<Company>())
            .ExposeConfiguration(cfg => new SchemaExport(cfg)
            .Create(false, false))  // this is intentionally set false , bcz i dont want to regenerate table when application starts every time 
            .BuildSessionFactory();


    }

now problem come i create a view in sql looks like this

Sql View

CREATE VIEW [FeaturedCompanies] AS

   SELECT COUNT(Company.id) As Count FROM Company
   WHERE Name='Alias'

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

Pleas help me out and thanks in advance

what is tried so far

Class

public class FeaturedCompany
{
    public virtual int id { get; set; }
    public virtual int name { get; set; }
    public virtual int count { get; set; }
}

Mapping

public class FeaturedCompanyMap : ClassMap<FeaturedCompany>
  {
 public FeaturedCompanyMap()
 {
    Table("FeaturedCompanies");
    ReadOnly();
   Id(x => x.id);
   Map(x => x.name);
   Map(x => x.count);
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:54:58+00:00Added an answer on June 12, 2026 at 10:54 am

    Views are mapped the same way tables are mapped except that you should put Readonly() in the mapping to prevent accidently writing to it. Example:

    public class FeaturedCompanyMap : ClassMap<FeaturedCompany>
    {
        public FeaturedCompanyMap ()
        {
           Table("FeaturedCompanies");
           ReadOnly();
    
           Id(x => x.Id);
           Map(x => x.Name);
           Map(x => x.Count);
        }
    }
    

    Update: to get the counts

    var results = session.Query<FeaturedCompany>().Where(filter).List();
    
    foreach(var row in results.Select(r => "Alias: " + r.Name + "  Occurence: " + r.Count))
    {
        // print row to screen
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using: ASP.NET MVC3 Ninject 2 Fluent nHibernate I have 2 databases (DB1 & DB2).
I'm using (Fluent) NHibernate in an ASP.NET MVC3 project. I'm using the standard approach
I'm using Fluent NHibernate in an ASP.NET MVC3 project. I'm coding up a custom
I am using NHibernate/Fluent NHibernate in an ASP.NET MVC app with a MySQL database.
I'm using ASP.NET MVC + NHibernate + Fluent NHibernate and having a problem with
I thought of using Fluent nhibernate for data access with my asp.net mvc web
I'm using a fluent nhibernate with asp.net mvc and I not seeing anything been
Using Fluent NHibernate I need a clue how to map my Invoice class. public
I am using Fluent nHibernate for my persistence layer in an ASP.NET MVC application,
Hi is there good tutorial about using Fluent Nhibernate in asp.net/winforms application ? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.