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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:30:35+00:00 2026-06-15T10:30:35+00:00

I would like to do the simplest thing – fetch data from db. When

  • 0

I would like to do the simplest thing – fetch data from db. When I make a query and later call SubmitChanges() on DataContext object, all the fetched items are deleted from DB. Here’s the code:

SubmitChanges(); // nothing happened (it is OK)
List<Flashcard> list = (from f in FlashcardsTable
                        where f.Category.IsSelected
                              && !excluded.Contains(f.FlashcardId)
                        select f).ToList();
SubmitChanges(); // All items from list are deleting from DB!!

FlashcardsTable is a table in DB, excluded is just a list with integers.

My question is why data from DB is deleted when SubmitChanges() is called and how to fix it (I want to leave the data in the database).


I’m still searching answer for my questions… Here are more details from my code, maybe it helps?

I do 2 things in my app. First create 100 items and put them to DB:

var db = new DbContext();
var flashcard = new Flashcard();
// here sets some fields on flashcard, not important...
for (var i = 0; i < 100; i++)
{
    var cat = db.CategoriesTable.First(c => c.CategoryId == categoryId);
    cat.Count++;
    flashcard.Category = cat;
    flashcard.BasketNr = 1;
    flashcard.TimeToCheck = Utils.CurrentDate.AddHours(12);
    db.FlashcardsTable.InsertOnSubmit(new Flashcard(flashcard));
}
db.SubmitChanges();

Next I make a query on DB:

var db = new DbContext();
db.SubmitChanges(); // here is OK, no SQL was generated
var a = (from f in db.FlashcardsTable
         where f.Category.IsSelected
         select f).ToList();
db.SubmitChanges(); // here are generated 100 SQLs deleting my data

After call second db.SubmitChanges() are generated 100 SQLs like:

DELETE FROM [Flashcard] WHERE [FlashcardId] = @p0

-- @p0: Input Int32 (Size = 4; Prec = 0; Scale = 0) [1]

-- Context: SqlProvider(SqlCE) Model: AttributedMetaModel Build: System.Data.Linq, Version=7.0.0.0, Culture=neutral, PublicKeyToken=24EEC0D8C86CDA1E

Maybe definitions of Tables are wrong? Here it is:

[Table]
public class Category : INotifyPropertyChanged {

    public event PropertyChangedEventHandler PropertyChanged;

    private string name;
    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int CategoryId { get; set; }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public string Name {
        get { return name; }
        set {
            if (name != value) {
                name = value;
                if (PropertyChanged != null) {
                    PropertyChanged(this, new PropertyChangedEventArgs("Name"));
                }
            }
        }
    }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public int Count { get; set; }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public bool IsSelected { get; set; }

}



[Table]
public class Flashcard {
    public const int TYPE_TEXT = 1;
    public const int TYPE_BITMAP = 2;

    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int FlashcardId { get; set; }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public DateTime TimeToCheck { get; set; }

    [Column(CanBeNull = false, UpdateCheck = UpdateCheck.Never)]
    public int Type { get; set; }

    private byte[] firstPageBitmap;
    private byte[] secondPageBitmap;
    private string firstPageText;
    private string secondPageText;

    public Flashcard(Flashcard flashcard) {
        FirstPageBitmap = flashcard.FirstPageBitmap;
        SecondPageBitmap = flashcard.SecondPageBitmap;
        FirstPageType = flashcard.FirstPageType;
        SecondPageType = flashcard.SecondPageType;
        BasketNr = flashcard.BasketNr;
        Category = flashcard.Category;
        TimeToCheck = flashcard.TimeToCheck;
    }

    public Flashcard() {
    }

    [Column(DbType = "image", UpdateCheck = UpdateCheck.Never, CanBeNull = true)]
    public byte[] FirstPageBitmap {
        get { return firstPageBitmap; }
        set {
            FirstPageType = TYPE_BITMAP;
            firstPageBitmap = value;
        }
    }

    [Column(CanBeNull = true, UpdateCheck = UpdateCheck.Never)]
    public string FirstPageText {
        get { return firstPageText; }
        set {
            FirstPageType = TYPE_TEXT;
            firstPageText = value;
        }
    }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public int FirstPageType { get; set; }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public int SecondPageType { get; set; }

    [Column(DbType = "image", UpdateCheck = UpdateCheck.Never, CanBeNull = true)]
    public byte[] SecondPageBitmap {
        get { return secondPageBitmap; }
        set {
            SecondPageType = TYPE_BITMAP;
            secondPageBitmap = value;
        }
    }

    [Column(CanBeNull = true, UpdateCheck = UpdateCheck.Never)]
    public string SecondPageText {
        get { return secondPageText; }
        set {
            SecondPageType = TYPE_TEXT;
            secondPageText = value;
        }
    }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public int BasketNr { get; set; }

    [Column(UpdateCheck = UpdateCheck.Never)]
    public int CatId { get; set; }

    [Association(ThisKey = "CatId", OtherKey = "CategoryId", IsForeignKey = true, DeleteOnNull = true)]
    public Category Category { get; set; }
}

Any suggestions?

  • 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-15T10:30:36+00:00Added an answer on June 15, 2026 at 10:30 am

    I figured it out. After change declaration of association Flashcard->Category everything works fine. Right code is here:

    private EntityRef<Category> _categoryRef = new EntityRef<Category>();
    [Association(ThisKey = "CatId", OtherKey = "CategoryId", IsForeignKey = true, DeleteOnNull = true, Storage = "_categoryRef")]
    public Category Category
    {
        get { return _categoryRef.Entity; }
        set
        {
            if (_categoryRef.Entity != value || !_categoryRef.HasLoadedOrAssignedValue)
            {
                _categoryRef.Entity = value;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The simplest example would be the built in class keyValuePair(of T,U). I would like
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like to make anapplication in Java that will not automatically parse parameters used
Very simple thing I'm trying to do here. I would like to have 2
I would like to make a bot that can carry on a simple conversation.
I would like to learn how to write the simplest server/client C++ command line
I have a static site. I would like the simplest approach to password protecting
I would guess it's the simplest thing but it's really confusing me. I'm sure
I am new to doing this sort of thing but I would like to
Would like a for loop in jquery so that: For every hover_link: show hidden

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.