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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:09:20+00:00 2026-05-13T11:09:20+00:00

I am using Fluent Nhibernate 1.0 with Sharp Architecture 1.0 Currently I am trying

  • 0

I am using Fluent Nhibernate 1.0 with Sharp Architecture 1.0

Currently I am trying to map a reference to a ZipCode class. The current class I am mapping has a ZipCode column, but the zipcode class is much more extensive than what is needed for a basic zipcode, hence the reasoning behind this. (Basically Zipcode class contains lat. and long. UTC time zone etc, all things that are readonly)

This is my mapping

            References<ZipCode>(x => x.ZipCodeRadius, "ZipCode")
            .Column("ZipCode")
            .Cascade.None()
            //.ForeignKey("FK_ZipCode")
            .ReadOnly();

and when I am running my tests, I am getting this error.

Initialization method CountryRepositoryTests.SetUp threw exception. System.Data.SqlClient.SqlException: System.Data.SqlClient.SqlException: Column ‘ZipCode.ZipCodeID’ is not the same data type as referencing column ‘Address.ZipCode’ in foreign key ‘FK8C1490CB2993CD44’.
Could not create constraint. See previous errors..

I have tried adding the ForeignKey and the Constrained lambdas, but they seemed to not add anything.

The zipcode tables has an ID, but I do not want to map to that, rather I want to map to the zipcode column of the zipcode table, back to the zipcode column of the address table.

If anyone has any ideas how I can get around this, I would really appreciate it.

Please note as I did above, I can not simply just reference the zipcode table and drop the property on the address because the zipcode table is readonly.

This is the ZipCodeRadius class.

[NotNullNotEmpty, Length(Max = 5)]
public virtual string ZipCodeName { get; set; }
[NotNullNotEmpty, Length(Max = 1)]
public virtual string ZipType { get; set; }
[NotNullNotEmpty, Length(Max = 10)]
public virtual string TimeZone{ get; set; }

public virtual int UTC  { get; set; }

public virtual double Latitude { get; set; }
public virtual double Longitude { get; set; }

public virtual County County { get; set; }

This is the Address class

protected Address() { }

public Address(User UpdateUser)
    : base(UpdateUser)
{
    this.UpdateUserId = UpdateUser.Id.ToString();  
}

//[DomainSignature, NotNullNotEmpty]
//public virtual string Title { get; set; }

[NotNullNotEmpty, Length(Max = 50)]
public virtual string AddressLine1 { get; set; }

[Length(Max = 50)]
public virtual string AddressLine2 { get; set; }

[NotNullNotEmpty, Length(Max = 20)]
public virtual string City { get; set; }

public virtual StateOrProvince State { get; set; }

[NotNullNotEmpty, Length(Max = 10)]
public virtual string ZipCode { get; set;}

[Length(Max = 10)]
public virtual string ZipPlus { get; set; }

public virtual bool IsVerified { get; set; }

public virtual Country Country { get; set; }

public virtual ZipCode ZipCodeRadius { get; set; }

This is the ZipCode table mapping

Table("ZipCode");

Id(x => x.Id, "ZipCodeID");

Map(x => x.ZipCodeName, "ZipCode").AsVarChar(5);
Map(x => x.ZipType, "ZipType").AsVarChar(1);
Map(x => x.TimeZone, "TimeZone").AsVarChar(10);
Map(x => x.UTC, "UTC");
Map(x => x.Latitude, "Latitude");
Map(x => x.Longitude, "Longitude");

ReadOnly();
Cache.ReadOnly();
  • 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-05-13T11:09:21+00:00Added an answer on May 13, 2026 at 11:09 am

    Apparently HasOne is the proper way to do this…. Even though I thought I tried it, I was missing the PropertyRef…

                HasOne<ZipCode>(x => x.ZipCodeRadius)
                .PropertyRef(x => x.ZipCodeName)
                .ForeignKey("ZipCode");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Fluent NHibernate to map a a class that has a collection of
I have a Sharp Architecture based app using Fluent NHibernate with Automapping. I have
Using Sharp Architecture / Fluent NHibernate, I set-up a Version property (with an int
Using Fluent NHibernate I need a clue how to map my Invoice class. public
I have dictionary which I'm mapping using Fluent NHibernate. The dictionary has a complex
I'm using Fluent NHibernate (Auto Mapping) to map my domain objects to database tables.
I have 3 classes that I'm trying to map using fluent nHibernate, but I've
I'm using Fluent NHibernate auto mapping. I need to access more than one database
I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in
Currently I'm using Fluent NHibernate to generate my database schema, but I want the

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.