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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:10:44+00:00 2026-06-08T18:10:44+00:00

I am moving from CodeFirst to DatabaseFirst to map my views. In my CodeFirst

  • 0

I am moving from CodeFirst to DatabaseFirst to map my views. In my CodeFirst approach I had a base entity like this:

public abstract class BaseEntity
{
    /// <summary>
    /// Gets or sets the entity identifier
    /// </summary>
    public virtual int Id { get; set; }
... // Some more methods here for equality checking
}

I derived all my classes from this base class, since every one of them would have an Id. So I used this BaseClass to create a generic repository. My repository looks like this:

public partial class EfRepository<T> where T : BaseEntity
{
    public readonly DemirbasContext context;
    private DbSet<T> _entities;

    /// <summary>
    /// Ctor
    /// </summary>
    /// <param name="context">Object context</param>
    public EfRepository(DemirbasContext context)
    {
        this.context = context;
    }

    public T GetById(object id)
    {
        return this.Entities.Find(id);
    }

    public void Insert(T entity)
    {
        try
        {
            if (entity == null)
                throw new ArgumentNullException("entity");

            this.Entities.Add(entity);

            this.context.SaveChanges();
        }
        catch (Exception e)
        {
        ...
        }
    }
    // Other methods here Update, Delete etc

So I was able to create repositories just by specifying the generic type paremeter like this

EfRepository<Car> carRepo = new EfRepository<Car>();

In DatabaseFirst, I cannot derive the entity classes from a base class. Is there a way to do it or what would be your suggestions?

  • 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-08T18:10:45+00:00Added an answer on June 8, 2026 at 6:10 pm

    Oops, I missed code generators.

    Right click on your data model (.EDM file) and click Add Code Generation Item. Choose DbContext (for simplified DbContext API).

    This creates two files with .tt extensions: One for context and one for entities. If you expand the file, you will see .tt file holds all your classes there.

    You can modify it as you need.

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

Sidebar

Related Questions

We are considering moving from Entity Framework to PLINQO L2S. EF has proven to
We are considering moving from Delphi 7 to Delphi 2009 and would like to
We're moving from php4 to php5, and we get this warning on one of
I am currently moving from C to Objective-C and, to me, this code seems
(This is a post that I'm moving from ui stackexchange. ) We have some
In my developments I am slowly moving from an object-oriented approach to interface-based-programming approach.
If you're going to be moving from LINQ to SQL to the Entity Framework
Im moving from django to pylons, is there an admin app?
As I am moving from C# to Python, I was wondering if there is
I'm moving from adobe flex to ext js 4, and I noted that in

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.