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

  • Home
  • SEARCH
  • 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 8730221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:58:34+00:00 2026-06-13T08:58:34+00:00

Entity Framework v5 looks cool and I try to switch from Linq-to-SQL with existing

  • 0

Entity Framework v5 looks cool and I try to switch from Linq-to-SQL with existing MSSQL (Azure) database.
but tutorials about EF are too complex to follow.

The database schema is pretty simple as follows (generated by exist db).

Sheets and SheetDetails tables are connected with 1-to-many relationship.

CREATE TABLE [dbo].[Sheets] (
    [Id]          INT            IDENTITY (1, 1) NOT NULL,
    [Grade]       FLOAT (53)     CONSTRAINT [DF_Sheets_Grade] DEFAULT ((0)) NOT NULL,
    [Title]       NVARCHAR (255) CONSTRAINT [DF_Sheets_Title] DEFAULT ('') NOT NULL,
    [Description] NVARCHAR (255) NULL,
    [Difficulty]  SMALLINT       CONSTRAINT [DF_Sheets_Difficulty] DEFAULT ((0)) NOT NULL,
    [Writer]      NVARCHAR (255) CONSTRAINT [DF_Sheets_Writer] DEFAULT ('') NOT NULL,
    [Tag]         NVARCHAR (255) NULL,
    [Duration]    FLOAT (53)     CONSTRAINT [DF_Sheets_Duration] DEFAULT ((0)) NOT NULL,
    [Timestamp]   DATETIME       CONSTRAINT [DF_Sheets_Timestamp] DEFAULT ((0)) NOT NULL,
    [RowVersion]  ROWVERSION     NOT NULL,
    CONSTRAINT [PK_Sheets] PRIMARY KEY CLUSTERED ([Id] ASC)
);

CREATE TABLE [dbo].[SheetDetails] (
    [Id]                   INT        IDENTITY (1, 1) NOT NULL,
    [Score]                FLOAT (53) CONSTRAINT [DF_SheetDetails_Score] DEFAULT ((0)) NOT NULL,
    [Number]               SMALLINT   CONSTRAINT [DF_SheetDetails_Number] DEFAULT ((0)) NOT NULL,
    [SubNumer]             SMALLINT   NULL,
    [IsRandom]             BIT        CONSTRAINT [DF_SheetDetails_IsRandom] DEFAULT ((0)) NOT NULL,
    [AnswerType]           SMALLINT   CONSTRAINT [DF_SheetDetails_AnswerType] DEFAULT ((0)) NOT NULL,
    [RowVersion]           ROWVERSION NOT NULL,
    [SheetDetail_Sheet]    INT        CONSTRAINT [DF_SheetDetails_SheetDetail_Sheet] DEFAULT ((0)) NOT NULL,
    [SheetDetail_Question] INT        CONSTRAINT [DF_SheetDetails_SheetDetail_Question] DEFAULT ((0)) NOT NULL,
    CONSTRAINT [SheetDetail_Sheet] FOREIGN KEY ([SheetDetail_Sheet]) REFERENCES [dbo].[Sheets] ([Id]) ON DELETE CASCADE
);

Note that the FK name is SheetDetail_Sheet in SheetDetails table.

Result diagram is as below.
enter image description here

Next, maybe I need to write EntityTypeConfiguration.
I tried it as question 1.

Question 1.
I wrote model creating configuration as follows but no luck. is it wrong? hard to know how to write right configuration with this simple database model.

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new SheetsConfiguration());
        base.OnModelCreating(modelBuilder);
    }

    public class SheetsConfiguration : EntityTypeConfiguration<Sheets>
    {
        public SheetsConfiguration()
            : base()
        {
            HasKey(p => p.Id);
            Property(p => p.Id).HasColumnName("Id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity).IsRequired();
            Property(p => p.RowVersion).IsConcurrencyToken().IsRowVersion();
            HasOptional(p => p.SheetDetails).WithMany().Map(x => x.MapKey("SheetDetail_Sheet"));
            ToTable("Sheets");
        }
    }

I execute simple query using

var result = _db.Sheets.Where(sheet => sheet.Id == id).ToList();

And then, I got an error “Invalid column name SheetDetail_Sheet” with executed query as follows.

SELECT 
[Extent1].[Id] AS [Id], 
[Extent1].[Grade] AS [Grade], 
[Extent1].[Title] AS [Title], 
[Extent1].[Description] AS [Description], 
[Extent1].[Difficulty] AS [Difficulty], 
[Extent1].[Writer] AS [Writer], 
[Extent1].[Tag] AS [Tag], 
[Extent1].[Duration] AS [Duration], 
[Extent1].[Timestamp] AS [Timestamp], 
[Extent1].[RowVersion] AS [RowVersion], 
[Extent1].[SheetDetail_Sheet] AS [SheetDetail_Sheet]
FROM [dbo].[Sheets] AS [Extent1]
WHERE [Extent1].[Id] = @p__linq__0

I can understand because SheetDetail_Sheet is just an FK and not exist in the edmx properties and database column.
How can I fix it?

I don’t want to edit auto-generated model file because it can be overwritten. maybe it seems to be achieved with EntityTypeConfiguration.

Question 2.
Is there any useful and lightweight reference with the commonly used master-detail database model?

I’m in trouble to start with existing database.
stackoverflow, asp.net, blogs, etc…to many tutorials but hard to find an example like my case.

Thank you.

  • 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-13T08:58:35+00:00Added an answer on June 13, 2026 at 8:58 am

    I’d suggest using Model First to create your database model (though you’re using database first). A good article for getting the database model is here. Just ignore the MVC stuff, and stop at “Generating Strongly Typed Entity Classes” as you are using EF5 which will generate the POCO classes for you. The Edmx should handle all of the FKs and properties for you and you won’t need to worry about the configurator.

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

Sidebar

Related Questions

Just wondering how the following sql query would look in linq for Entity Framework...
I have a LINQ query mapped with the Entity Framework that looks something like
I currently have an Entity Framework model that collects data from a legacy database
The method - Entity Framework Code-First - looks good. But its very difficult to
Normally the code for using the dbContext from Entity Framework looks something like this:
I have an Entity in Code First Entity framework that currently looks like this:
A one-many or many-many relationship in Entity Framework Code First looks like this:- public
What is the best solution for many-to-many joins in Entity Framework. It looks like
Entity framework is cripplingly slow so I tried using a stored procedure but I
Do Entity Framework functions automatically escape input to protect against injection? In my SQL

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.