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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:35:03+00:00 2026-05-21T06:35:03+00:00

I am working on an asp.net application. I need help designing the database related

  • 0

I am working on an asp.net application. I need help designing the database related model and linq queries.

I have three tables ( and two lookup tables).

1)Product header (product header id as Primary key)
2) Product Detail(it has product header id as foreign key)
3) product attachment (it has product detail id as foreign key)

Now, I need to insert record in db.

a) for one Product header record there can be multiple Product detail records
b) for multiple product detail records, there can be multiple attachments.

I have created three entities for each tables. Product header also has two keys from user table and history table. but on view I need to show the user name instead of the key. Should I create a view model class which will hold all these entity classes as properties and how can I make sure that there first record is inserted in product header, then product details and then product attachment ?

Please suggest.

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-05-21T06:35:04+00:00Added an answer on May 21, 2026 at 6:35 am

    an easy way to do this is to use the new Code First Feature that comes with EF 4.1

    you can create your “entities” like so:

    public class ProductHeader
    {
       public int ID {get; set;}
    
       public virtual ICollection<ProductDetail> ProductDetails {get; set;}
    
       //Other properties
    }
    
    public class ProductDetail
    {
       public int ID {get; set;}
    
       public virtual ICollection<ProductAttachment> ProductAttachments {get; set;}
    
       //Other properties
    }
    
    public class ProductAttachment
    {
       public int ID {get; set;}
    
       // you can have a navigation property here for the user, this allows you to access his name
       public virtual User User {get; set;}
       //Other properties
    }
    
    public class MyContext:DbContext
    {
        public DbSet<ProductHeader> ProductHeaders {get; set;}
        public DbSet<ProductDetail> ProductDetails {get; set;}
        public DbSet<ProductAttachment> ProductAttachment {get; set;}
    }
    

    for the insertion order, just add your ProductHeader (after adding the ProductDetails and ProductAttachments to it) and EF will take care of it.

    EDIT:
    here’s a sample code for adding a ProductHeader:

    var context=new MyContext();
    var ph=new ProductHeader();
    ph.User=user;
    var pd=new ProductDetail();
    pd.ProductAttachments.Add(new ProductAttachment());
    ph.ProductDetails.Add(pd);
    context.ProductHeaders.Add(ph);
    context.SaveChanges();
    

    Hope this helps.

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

Sidebar

Related Questions

I am working on an ASP.NET MVC application where I need to export data
I'm working on an asp.net application which uses Lucene.net I need to highlight the
I have been developing an asp.net mvc application where i need to make large
ASP.NET 4.0 Need some help with this vexing HTTP POST problem - I have
I am working on ASP.NET application. I try to connect to database in Adaptive
I am working on asp.net MVC application. I have a folder with some sub
I'm working on a multi-tenant ASP.NET MVC application. So far we have been using
I am working on a ASP.net application written in C# with Sql Server 2000
I'm working on an ASP.Net application and working to add some Ajax to it
I am currently working on an asp.net application in Visual Studio 2005. I would

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.