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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:48:29+00:00 2026-06-09T07:48:29+00:00

We have a performance problem with EF (Entity Framework). The first screen that calls

  • 0

We have a performance problem with EF (Entity Framework). The first screen that calls EF takes much more time to open than the second one. There is no difference in the loading time if the second screen is the same as the first or a completely different one; all other screens will be fast.

We use the Code First API to create a ‘database First’ version of EF. To do this, we use T4 Templates to generate our entities class from the database table. One class is created by table. They are mapped in ‘OnModelCreating()’ We decided to go this way because we needed to separate our entity in three different layers (namespaces and assemblies):

  1. Common Framework
  2. Project Framework
  3. Project Sector

The entities of each of these layers need to be linked to other entities in the previous layers. We tried to use edmx files but we did not find how to put the entities in different namespaces in the same edmx.

We also generate additional classes that are linked to the entities class. Presently, with our T4 Template we generate additional classes that the programmer can use to extend the entities property or to add validation.

The generated entities are the classes that the T4 Template creates with properties for every table column. The Entities is a class that extends the generated class where the programmer can add code. This is the class that is mapped to the table. The validator class is called when the other classes are modified or when the data is saved to database.
We need to find a way to pre-generate our view with code first or to have the same flexibility of code first with the edmx.

Example:

ParameterBase.Generated.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Xml.Linq;
using Keops.Common.Data;
using Keops.Common.Validation;
using Keops.Common.Validators.Framework;

namespace Keops.Common.Entities.Framework
{
    public abstract class ParameterBase
        : EntityBase
        , IHaveAValidator
        , IDatabaseOriginAware
    {
        protected ParameterBase()
        {
            ParameterValueList = new HashSet<ParameterValue>();
            Validator = new ParameterValidator((Parameter)this);
        }

        #region Database columns

        public string Code
        {
            get { return _code; }
            set
            {
                if (_code != value)
                {
                    _code = value;
                    RaisePropertyChanged("Code");
                }
            }
        }
        private string _code;

        public bool IsEditable
        {
            get { return _isEditable; }
            set
            {
                if (_isEditable != value)
                {
                    _isEditable = value;
                    RaisePropertyChanged("IsEditable");
                }
            }
        }
        private bool _isEditable;

        public bool IsVisible
        {
            get { return _isVisible; }
            set
            {
                if (_isVisible != value)
                {
                    _isVisible = value;
                    RaisePropertyChanged("IsVisible");
                }
            }
        }
        private bool _isVisible;

        public int ParameterID
        {
            get { return _parameterID; }
            set
            {
                if (_parameterID != value)
                {
                    _parameterID = value;
                    RaisePropertyChanged("ParameterID");
                }
            }
        }
        private int _parameterID;

        public int ValueTypeID
        {
            get { return _valueTypeID; }
            set
            {
                if (_valueTypeID != value)
                {
                    _valueTypeID = value;
                    RaisePropertyChanged("ValueTypeID");
                }
            }
        }
        private int _valueTypeID;

        public string Name
        {
            get { return _name; }
            set
            {
                if (_name!= value)
                {
                    _ name = value;
                    RaisePropertyChanged("Name ");
                }
            }
        }
        private string _ name;

        #endregion Database columns

        #region Navigation parents

        [ForeignKey("ValueTypeID")]
        public ValueType ValueType
        {
            get { return _valueType; }
            set
            {
                if (_valueType != value)
                {
                    _valueType = value;
                    ValueTypeID = value == null
                        ? 0
                        : value.ValueTypeID;
                    RaisePropertyChanged("ValueType");
                }
            }
        }
        private ValueType _valueType;

        #endregion Navigation parents

        #region Navigation children

        public virtual ICollection<ParameterValue> ParameterValueList { get; set; }

        #endregion Navigation children

        #region IHaveAValidator

        public ValidatorBase<Parameter> Validator { get; private set; }

        IValidator IHaveAValidator.Validator
        {
            get { return Validator; }
        }

        #endregion

        #region IDatabaseOriginAware

        public bool IsFromDatabase { get; set; }

        string IDatabaseOriginAware.FullTableName { get { return "Framework.Parameter"; } }       

        #endregion
    }
}

Parameter.cs

namespace Keops.Common.Entities.Framework
{
    public class Parameter : Parameter Base
    {
        //Add custom methods here
    }
}

ParameterValidatorBase.Generated.cs

using System;
using System.Data.Entity;
using System.Linq.Expressions;
using Keops.Common.Entities.System;
using Keops.Common.Validation;

namespace Keops.Common.Validators.System
{
    public abstract class ParameterValidatorBase : ValidatorBase<Parameter>
    {
        private readonly Parameter _entity;

        protected ParameterValidatorBase(Parameter entity)
            : base(entity)
        {
            _entity = entity;
        }

        protected ParameterEntity { get { return _entity; } }
    }
}

ParameterValidator.cs

using Keops.Common.Entities.System;

namespace Keops.Common.Validators.System
{
    public class ParameterValidator : ParameterValidatorBase
    {
        internal ParameterValidator(Parameter entity)
            : base(entity)
        {
        }

        //Define custom rules here
    }
}
  • 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-09T07:48:30+00:00Added an answer on June 9, 2026 at 7:48 am

    After more research, we found a blog post from Pawel Kadluczka:

    Entity Framework Code First View Generation Templates On Visual Studio Code Gallery

    He created a T4 Template that can be used to generate view from Code First.

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

Sidebar

Related Questions

I have a blog application that models a database using Entity Framework. The problem
I have a performance problem on a query. First table is a Customer table
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
The problem: I have a WCF service that I'm trying to performance test with
In entity framework I have an Entity 'Client' that was generated from a database.
I am encountering some performance problems with my Entity Framework Code-First queries and I
Using LINQ to Entities with Entity Framework and C#: I have a method that
I currently working on a application that use Entity Framework 4.1 (code first) and
I'm having a problem with performance with the entity framework. Here's the scenario. I
I am using Entity Framework with my website. To improve performance, I have started

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.