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 7998571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:14:46+00:00 2026-06-04T15:14:46+00:00

this is almost the same as this question except using NH’s mapping-by-code. I really

  • 0

this is almost the same as this question except using NH’s mapping-by-code.

I really need the virtual properties because i also want to use SchemaExport to create the database for different rdbms without the need to create/maintain scripts for each.

Maybe there is a MbC Guru who knows how to do it with MbC

Update: the obvious simple code

Property("dummyProperty", c =>
{
    c.Column("legacyColumn");
    c.Access(typeof(MyPropertyAccessor));
});

does not work

NHibernate.MappingException: Unable to instantiate mapping class (see InnerException): Test.MbC.GroupMap ---> System.Reflection.TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht. ---> NHibernate.MappingException: Member not found. The member 'dummyProperty' does not exists in type Test.Data.Group
   bei NHibernate.Mapping.ByCode.Impl.CustomizersImpl.PropertyContainerCustomizer`1.GetPropertyOrFieldMatchingNameOrThrow(String memberName)
   bei NHibernate.Mapping.ByCode.Impl.CustomizersImpl.PropertyContainerCustomizer`1.RegisterNoVisiblePropertyMapping(String notVisiblePropertyOrFieldName, Action`1 mapping)
   bei 
   ...

neither does this, because god knows why MbC checks internally with reflection, that the property does exist on the class.

var parameter = Expression.Parameter(typeof(T), "x");
Expression body = Expression.Property(parameter, new GetterPropertyInfo(typeof(T), defaultgetter));
body = Expression.Convert(body, typeof(object));

var lambda = Expression.Lambda<Func<T, object>>(body, parameter);

Property(lambda, m =>
{
    m.Column(defaultgetter.PropertyName);
    m.Access(propertyAccessorType);
});

and even disabling the test with reflection through overriding RegisterProperty() in ClassMapping it still throws while building the hbm complaining:

System.ArgumentOutOfRangeException: Can't add a property of another graph
Parametername: property
   bei NHibernate.Mapping.ByCode.Impl.AbstractBasePropertyContainerMapper.Proper
ty(MemberInfo property, Action`1 mapping)
   bei NHibernate.Mapping.ByCode.ModelMapper.MapProperty(MemberInfo member, Prop
ertyPath propertyPath, IMinimalPlainPropertyContainerMapper propertiesContainer)

   bei NHibernate.Mapping.ByCode.ModelMapper.MapProperties(Type propertiesContai
nerType, IEnumerable`1 propertiesToMap, IPropertyContainerMapper propertiesConta
iner, PropertyPath path)
   bei NHibernate.Mapping.ByCode.ModelMapper.MapProperties(Type propertiesContai
nerType, IEnumerable`1 propertiesToMap, IPropertyContainerMapper propertiesConta
iner)
   bei NHibernate.Mapping.ByCode.ModelMapper.MapRootClass(Type type, HbmMapping
mapping)
   bei NHibernate.Mapping.ByCode.ModelMapper.CompileMappingFor(IEnumerable`1 typ
es)

Mapping by code should be more flexible than FNH? Where?

  • 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-04T15:14:48+00:00Added an answer on June 4, 2026 at 3:14 pm

    After investing a lot of time trying to do this rather simple mapping in MbC i concede and throw aboard MbC again.

    Even simple Mapping like this is not remotely possible with the oh so flexible MbC

    public class MyClassMap : ClassMap<MyClass>
    {
        public MyClassMap()
        {
            Map(x => this.VirtualProp, "legacyColumn").Default("123").Access.None();
        }
    
        public long VirtualProp { get; set; }
    }
    

    the advantage here is that i can use SchemaExport to create a compatible schema for the legacy app without polluting my domain classes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is almost the same question than here , except that I am asking
In reference to this question, I am facing almost the same scenario except that
My question is almost exactly the same as this post , except that I'm
This question is almost the same as a previous question , but differs enough
Almost the same question as this one here: What's the easiest way to grab
I asked the almost the same question before also, but i have not yet
This is almost exactly the same as this question json get key names as
I have almost the same problem as this unanswered question . The only difference
After viewing answer of almost a same question on SO i added this line
I asked Almost this exact same question yesterday. Basically I have a css button

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.