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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:14:31+00:00 2026-06-05T11:14:31+00:00

I need to design domain that has two simple entities: public class User {

  • 0

I need to design domain that has two simple entities:

public class User
{
    public virtual int Id { get; protected set; }
    public virtual string Email { get; protected set; }
    public virtual Country Country { get; protected set; }
    ...
}

public class Country
{
    public virtual int Id { get; protected set; }
    public virtual string Name { get; protected set; }
    ...
}

It’s all nice and clear in domain world but the problem is that User and Country persisted in two different databases on two different servers (tho they are both MSSQL 2005 servers).

So, how should I correctly implement persistance of entites across different sql servers in NHibernate?

Using IDs instead of objects in references? Yeah, thats simple but it’s hitting hard on the whole domain thing making domain object more like DTO. And it will require that IUserRepository get it’s hands on ICountryRepository to load User entity.

Linked servers? Hm… Somehow I don’t like it (distributed transactions and no XML columns). And what I should be aware in case of using them and more importantly how should I configure NHibernate to work effectively with linked servers?

Maybe some other solution?

  • 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-05T11:14:32+00:00Added an answer on June 5, 2026 at 11:14 am

    I’ve heard of people using the schema property in a class mapping to contain the linked server name (like otherserver.dbo), but I don’t know anyone that hasn’t ran into one problem or another when doing that.

    There are a few DDD bootstrapping frameworks that allow you to transparently map entities to different databases (resulting in multiple ISessionFactories, which it will manage for you). NCommon is one I would recommend. This assumes, however, that Country only exists in one database, and User only exists in another.

    As for transactions… well, if you use a TransactionScope and configure DTS, that might work. NCommon uses a UnitOfWork API that also wraps TransactionScope.

    You would have to change User so that Country is just an ID. Here’s why. You’d end up with two session factories, one that has a mapping for Country and the other that has a mapping for User. If you don’t make that change, NHibernate will complain that there is no mapping for Country when you save User (since they are stored in two different DBs).

    Now you could instruct NHibernate to ignore Country property, and keep Country so your domain doesn’t change. However, when you load User from the database next time, Country will be null.

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

Sidebar

Related Questions

I have the following entities in Entity Framework: public class School { public int
Need to design a simple one for school. More specifically a Moore FSM. Im
I need to design a Turing Machine Simulator in C++ that takes in an
I need to design a executable .jar which makes two text files, I want
I need to design a data structure that supports the following operations: search element
I need to design a simple piece of software, and i was wondering the
I need to design a system that will control access to certain information. The
I need to design a page for a web application that makes sense for
I'm trying to learn Domain Driven Design by example and I need your advice.
Lets say I have some domain objects that will need to be serialized/packed using

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.