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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:24:40+00:00 2026-06-06T21:24:40+00:00

Hi I have an existing database with a table with 30 fields, I want

  • 0

Hi I have an existing database with a table with 30 fields, I want to split the table into many models so I could retrieve/save fields that I need and not every time retrieve/save the whole object from the db. using c#.

I think I should be using Code-First. Could someone provide an example or a tutorial link?

thanks,

  • 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-06T21:24:42+00:00Added an answer on June 6, 2026 at 9:24 pm

    You don’t need to split table to be able to load a subset of field or persist subset of fields. Both operations are available with the whole table mapped to single entity as well.

    For selection you simply have to use projection:

    var data = from x in context.HugeEntities
               select new { x.Id, x.Name };
    

    You can use either anonymous type in projection or any non-mapped class.

    For updates you can simply use:

    var data = new HugeEntity { Id = existingId, Name = newName };
    context.HugeEntities.Attach(data);
    var dataEntry = context.Entry(data);
    dataEntry.Property(d => d.Name).IsModified = true; // Only this property will be updated
    context.SaveChanges();
    

    Or:

    var data = new HugeEntity { Id = existingId };
    context.HugeEntities.Attach(data);
    data.Name = newName; 
    context.SaveChanges(); // Now EF detected change of Name property and updated it
    

    Mapping multiple entities to single table must follows very strict rules and it is possible only with table splitting were all entities must be related with one-to-one relation (and there are some problems with more than two entities per split table in code first) or with table-per-hierarchy inheritance. I don’t think that you want to use any of them for this case.

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

Sidebar

Related Questions

I have a table in my database which has duplicate records that I want
I have an existing database(myDatabse) that I created with Microsoft Sql Managenent studio and
I have an existing database containing some pictures in blob fields. For a web
I have an existing database based on SQLiteOpenHelper that has several versions and code
My problem is I have an existing table that I can not modify that
I have a field in my mysql table that I want to update. Example:
I am working on a database that has an existing Individuals table that every
I have lists of about 20,000 items that I want to insert into a
I have a table with two fields in an sql server database and my
I have inherited a database I need to work with. All the numeric fields

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.