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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:53:21+00:00 2026-05-23T02:53:21+00:00

I develop a little object parser (for SQL files that allows me to find

  • 0

I develop a little object parser (for SQL files that allows me to find easily the list of all tables used in a procedure) and I’ve the following model :

3 tables :

  • Object (ID, Name, LastWriteTime)
  • Table (ID, Name)
  • ObjectTable (ObjectID, TableID)

I’ve the 3 corresponding classes :

Object – List of files scanned:

[Table(Name = "object")]
public class SourceFile : IEquatable<SourceFile>
{
    public SourceFile()
    { }

    [Column(Name = "id", IsDbGenerated = true)]
    public Guid ID
    {
        get;
        set;
    }

    [Column(Name = "lastwritetime")]
    public DateTime LastWriteTimeUtc
    {
        get;
        set;
    }

    [Column(Name = "name", IsPrimaryKey = true)]
    public String Name
    {
        get;
        set;
    }

    public bool Equals(SourceFile other)
    {
        return Name == other.Name;
    }

    public override int GetHashCode()
    {
        return Name.GetHashCode();
    }
}

Table – List of all tables in the DB:

[Table(Name = "table")]
public class SourceTable : IEquatable<SourceTable>
{
    public SourceTable()
    { }

    [Column(Name = "id", IsDbGenerated = true)]
    public Guid ID
    {
        get;
        set;
    }

    [Column(Name = "name", IsPrimaryKey = true)]
    public String Name
    {
        get;
        set;
    }

    public bool Equals(SourceTable other)
    {
        return Name == other.Name;
    }

    public override int GetHashCode()
    {
        return Name.GetHashCode();
    }
}

ObjectTable – For each object, the list of table used :

[Table(Name = "object_table")]
public class SourceFileTable
{
    [Column(Name = "object_id", IsPrimaryKey = true)]
    public Guid ObjectID
    {
        get; set;
    }

    [Column(Name = "table_id", IsPrimaryKey = true)]
    public Guid TableID
    {
        get; set;
    }
}

As you can see, the ID of object & table are DBGenerated, so my question is, how can I add values in ObjectTable using the generated IDs? There only given once inserted in DB, not before.

Any hint?

  • 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-23T02:53:22+00:00Added an answer on May 23, 2026 at 2:53 am

    If you add the entity objects that you have created, Linq-to-sql will figure it out for you. As long as your foreign keys are ok in the DB something like this will work:

    using (db = new datacontext())
    { 
        var parent = new parent();
        var child = new child();
        parent.children.ad(child);
        db.parents.insertonsubmit(parent);
        db.submitchanges();
     }
    

    So you do not add the keys but the objects. The same will work for an association like yours.

    Update
    In your case it will look like (by heart, so please check for typo’s)

    using (db = new datacontext())
    {
    var o = new Object();
    var t = new Table();
    db.objects.insertonsubmit(o);
    db.tables.insertonsubmit(t);
    var objecttable = new objecttable();
    objecttable.object = o;
    objeecttable.tbale = t;
    db.objecttables.insertonsubmit(objecttable);
    db.submitchanges();
    

    }

    Or is your question about how to define the foreign keys in the database? That is done with a statement like this:

    ALTER TABLE ORDERS 
    ADD FOREIGN KEY (customer_sid) REFERENCES CUSTOMER(SID); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop a little C# application (with MS Visual Express and SQL
We develop Win32 application that access to SQL 2005 database through Linq to SQL.
I plan to develop a nice little application that will run on an arm-based
I'm trying to develop a model object to hold a Sql Server row, and
I've been trying to develop a little library for reading MPQ files in Clojure,
I want to develop a little iPhone application, just for my personal needs. I
I have a quick little application and wanted to give a try to develop
I know a little about SNMP, but not enough. I need to develop an
For a little background, I work for a firm that develops web-based enterprise social
--I haven't develop any iPhone Web Application ever...so i am little bit confuse about

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.