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

  • Home
  • SEARCH
  • 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 9186107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:26:33+00:00 2026-06-17T19:26:33+00:00

I’m currently in the design phase of multiple rather complex systems which share common

  • 0

I’m currently in the design phase of multiple rather complex systems which share common functionality (e.g. both have customer-relationship management (CRM) and sales functionality). Therefore I’m trying to extract the common part of the domain and reuse it in both applications.

Let’s say I have application A and application B, both using CRM functionality. For the most part, the CRM functionality is the same, but both applications like to augment some things related to CRM.

I’d like to create a library implementing a basic version of the CRM system, e.g. a customer is abstracted to

interface ICustomer {
  string CustomerNumber {get;set;}
}

and the base library has a basic implementation of ICustomer

class Customer: ICustomer

Application A can now augment this:

interface IACustomer : ICustomer {
    bool ReceivesNewsletter {get;set;}
}

class ACustomer : Customer, IACustomer {
   ...
}

Likewise, B has its own variation:

interface IBCustomer : ICustomer {
    string NickName {get;set;}
}

class BCustomer : Customer, IBCustomer {
    ....
}

For the purpose of abstraction, I never instantiate concrete types in the base library but use a factory or a DI container, e.g.:

interface ICrmFactory {
    ICustomer CreateCustomer();
}

A and B implement the factory accordingly such that ACustomers or BCustomers are created respectively.

Here’s a UML diagram of what I mean (application B is not shown):
Application design

For persistence I use NHibernate. Both A and B provide their own mapping (mapping-by-code) to include the extra properties. In addition, A defines IACustomer to be the proxy type of ACustomer and B defines IBCustomer to be the proxy type of BCustomer.

I can now use NHibernate to work with the entities in A and B, e.g. in A

session.QueryOver<ACustomer>()
    .Where(c=>c.ReceivesNewsletter)
    .List()

Now let’s say I want to do something with customers in the base library (for example in some kind of service object). I’ve just prototyped a very simple version and so far this seems to work fine:

session.QueryOver<ICustomer>()
   .Where(c => c.CustomerNumber == "1234ABC")
   .List()

That is, I can use the base class of the proxy type of a specific entity in QueryOver, and NHibernate creates the correct query, e.g. in A:

SELECT
    this_.Id as Id0_0_,
    this_.CustomerNumber as Customer2_0_0_,
    this_.ReceivesNewsletter as Receives3_0_0_ 
FROM
    ACustomer this_ 
WHERE
    this_.CustomerNumber = @p0;
@p0 = '1234ABC' [Type: String (4000)] 

My question

Will those queries always work as expected? Can I always safely use a base type of the proxy interface in my queries in the base library? Will NHibernate always find the “correct” entity type and table to retrieve? Or will there be situations where this affects query efficiency adversely b/c NHibernate needs to do guess work? Any other pitfalls I should be aware of in this scenario?

I could not find information about this in the documentation. This approach would allow me to neatly move common parts of some domains to their own base libraries, but I want to make sure it works.

  • 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-17T19:26:35+00:00Added an answer on June 17, 2026 at 7:26 pm

    I do not see a problem with this scenario.
    Especially since there is only a single implementation to ICustomer in every application.

    Even if you would have had more than one implementation for every application, you could experience some problems with loading by id (session.Load(42), because there can be more than one customer with that id,depending on your mapping). but queries to recieve lists of customers would still have worked.

    When I looked into issues similar to yours with NHibernate in the past I read this article – its talks about a derived base class and not an interface,but it’s the same idea: http://codebetter.com/jameskovacs/2011/02/16/getload-polymorphism-in-nhibernate-3/

    NHibernate does no guess work – upon initialization it builds a store of all of the mappings it has for any given type,when you write a query for any kind of type it will find the correct types it has mapped that inherit from it and query accordingly.

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

Sidebar

Related Questions

I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.