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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:52:32+00:00 2026-05-31T06:52:32+00:00

I have 3 classes: BasePlace, Hall, HallPlan . Relations: BasePlace – Hall : one-to-many.

  • 0

I have 3 classes:
BasePlace, Hall, HallPlan.

Relations:
BasePlace - Hall: one-to-many.
Hall – HallPlan: one-to-many.

I get places(venues) from remote program. I have the following method to add(or update) object:

public void AddPremieraPlace(IEnumerable<BasePlace> places)
        {
            if(places != null)
            {
                foreach (var place in places)
                {
                    //is exist in db
                    var dbPlace = Database.BasePlaces.FirstOrDefault(p => p.OIDPremiera == place.OIDPremiera);
                    // if exist update properties and collections
                    if (dbPlace != null)
                    {
                        dbPlace.Name = place.Name
                        dbPlace.Halls = place.Halls;
                    }
                    else
                        Add(place); // just add new place

                    Database.SubmitChanges();                    
                } 

            }
        }

When place is exist in the DB then updates works not properly. In the Hall and HallPlan creates duplicate:
Hall table, for example:

OID   Name       PlaceId  OIDPremiera
19  Redisson        NULL        1
20  Test 2          NULL        3
21  Test 3          NULL        2

22  Redisson        5           1
23  Test 2          5           3
24  Test 3          5           2

How to update correctly?
Thanks.

Add():

public virtual void Add(TClass entity)
        {
            Check.Argument.IsNotNull(entity, "entity");

            Database.GetTable<TClass>().InsertOnSubmit(entity);
        }
  • 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-31T06:52:33+00:00Added an answer on May 31, 2026 at 6:52 am

    LINQ-to-SQL has an identity manager; if it finds something in the tree that it doesn’t recognise (i.e. isn’t in the identity manager), then it assumes it is to be treated as an insert for that item. So because it doesn’t recognise your Hall instances, it is inserting them.

    There are 2 ways to address this:

    • rather than directly assigning the Halls from your non-L2S model to the L2S model, you could ask the data-context for the matching instance, i.e. in a loop, use ctx.Halls.FirstOrDefault(...) to get the equivalent Hall from the data-context, and add that instead of the original
    • use the Attach method (i.e. ctx.Halls.Attach(...)) to make L2S aware of the hall instances before you start
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have classes Gallery and Image. There can be many images in one
I have classes that store data, and methods to go get data for individual
I have classes which have automatic properties only like public customerName {get; set;}. They
From what I have read best practice is to have classes based on an
I have two classes, and want to include a static instance of one class
I have classes such as AccountsController, ProductsController etc that all inherit from BaseController. Unity
I have classes like this one: class SomeObject { public function __construct($param1, $param2) {
We have classes public Invoice: EntityObject { public EntityCollection<InvoicePosition> Positions { get {...}; set{...};
I have classes like the following. That is many classes with the same few
I have classes which are inherited from abstract Packet( this class has abstract method

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.