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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:55:36+00:00 2026-05-31T02:55:36+00:00

I’m trying to convert a project that is currently using a custom DAO framework

  • 0

I’m trying to convert a project that is currently using a custom DAO framework to using Entity Framework. The system is quite large so changes to the database (a SQL Azure DB if that matters) itself aren’t particularly feasible and should be avoided if possible.

The problem is with the ID column. Unfortunately when the system was created, there are some tables that have a bigint datatype, and some that have an int – but the models themselves all come from a base class having a long for the ID. The previous framework was able to handle this situation, but I have been unable to find a way to do it with entity framework.

Below is the most trivial example I can think of:

public class Context : DbContext {
    public IDbSet<Foo> Foos {get;set;}
    public IDbSet<Bar> Bars {get;set;}
}
public abstract class BaseClass {
    public long ID;
}
public class Foo : BaseClass {
    ...
}
public class Bar : BaseClass {
    ...
}
SQL Table: Foo
+-------------+
| id : bigint |
| ...         |
+-------------+
SQL Table : Bar
+-------------+
| id : int    |
| ...         |
+-------------+

When I try to load a Bar model, I get this error:

The 'ID' property on 'BaseClass' could not be set to a 'Int32' value. You must set this property to a non-null value of type 'Int64'.

I’d like to find a way to tell the system that Bar has ints, while Foo has longs. I’ve tried overriding OnModelCreating in the context and defining HasColumnType for Bar. That gave me a new error:

Schema specified is not valid. Errors:
    (105,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Int64[Nullable=False,DefaultValue=]' of member 'ID' in type 'Bar' is not compatible with 'SqlServer.int[Nullable=False,DefaultValue=,StoreGeneratedPattern=Identity]' of member 'ID' in type 'CodeFirstDatabaseSchema.Bar'.

It seems to me that if I could only change the expected data type for the ID of BaseClass to int before sending the request to the server, then I should be able to up-convert to a long after I receive the response. Ideally, I’d like to do this on a per-class basis.

Can anyone point me in the right direction?

  • 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-31T02:55:37+00:00Added an answer on May 31, 2026 at 2:55 am

    While you can implicitly cast a bigint to an int in SQL Server, it appears that the Entity framework EDM types (which is really what you’re dealing with) doesn’t allow an implicit transformation from a 64-bit integer type to a 32-bit integer type.

    This is probably for good reason, because you could easily overflow and have values that don’t fit in the int fields.

    That said, you should have two base classes, one for an int ID and one for a long ID. It’s not pretty, but it enforces logic that you definitely want; you won’t be able to store values that are larger than what can fit into an int in the database, so why would you want to be able to do it on the code level? The Entity framework is doing the right thing here in not letting you apply that transformation.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.