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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:27:39+00:00 2026-05-26T11:27:39+00:00

I have an existing SQL Database in which all tables have an ID column

  • 0

I have an existing SQL Database in which all tables have an ID column as the primary key. Can I generate an Entity Framework Model from this database AND make sure all the generated types inherit from an interface that defines the ID property?

Basically, I want everything that I return from the database to implement this:

public interface IDatabaseTable
{
    public int ID { get; set; }
}
  • 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-26T11:27:39+00:00Added an answer on May 26, 2026 at 11:27 am

    I hope you using EntityFramework 4 if so you need to use T4 templates to generate your entity and data context, you may download that from here

    http://visualstudiogallery.msdn.microsoft.com/23df0450-5677-4926-96cc-173d02752313

    Than when you get it setup you would need to modify T4 template to generate inheritance.

    So you would get two tamplates one template which is generating Data Context and other one which is generating Entities.

    You need to modify the second one(entity generator template), go to line 41 of your entity .tt file and add your inheritance there like that:

    <#=Accessibility.ForType(entity)#> <#=code.SpaceAfter(code.AbstractOption(entity))#>partial class <#=code.Escape(entity)#><#=code.StringBefore(" : ", code.Escape(entity.BaseType))#> : IDatabaseTable
    

    Some details on T4 POCO tamplates you may find here

    http://sharedtolearn.blogspot.com/2010/06/entity-framework-40-and-t4-templates-to.html

    http://msdn.microsoft.com/en-us/data/gg558520

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

Sidebar

Related Questions

I have quick question for you SQL gurus. I have existing tables without primary
Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
I have an existing SQL Server database whose structure I can't really change, although
I have an existing SQL Server 2005 database that runs our accounting/inventory application. We
Scenario: I have an application (C#) that expects a SQL database and login, which
I have an existing SQL Server database, where I store data from large specific
I have all my SQL stored in source control in the following structure Database
I have an ASP.NET application with existing business classes and a database schema. (which
I have an SSIS package that takes data from Tables in an SQL database
Is there any way in which I can clean a database in SQl Server

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.