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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:03:34+00:00 2026-06-15T22:03:34+00:00

I start using BLToolkit and there is a new advantage: InsertOrReplace When I try

  • 0

I start using BLToolkit and there is a new advantage: InsertOrReplace
When I try to use it there is an exception:
“InsertOrUpdate method does not support identity field ‘Margin.id'”
My Model here:

[TableName("Margin")]
    public class Margin
    {
      [PrimaryKey, Identity]    public int      id;
      [NotNull]                 public string   StoreID;
      [PrimaryKey]              public int?     PrTypeID;
                                public decimal  MarginRate;
      [Association(ThisKey = "PrTypeID", OtherKey = "ProductID", CanBeNull = true)] public Product Product;

    }

Call the method:

 db.InsertOrReplace(new CSSWarranty.DataModel.DataModel.Margin()
                                      {
                                          MarginRate = newMargin.Margin,
                                          PrTypeID = newMargin.ProductTypeID == 0 ? null : newMargin.ProductTypeID,
                                          StoreID = newMargin.StoreID,
                                          id = newMargin.MarginID
                                      });

May be someone can say how to use the next construction: db.Margin.InsertOrUpdate(x,y)
All regards!

I don’t understand why this example is working:

[TableName("Notification")]
    public class Notification
    {
        [PrimaryKey]    public      string NotificationID;
                        public      string     Note;
    }

Call:

 var db = new RetailerDb()
db.InsertOrReplace(new DataModel.DataModel.Notification()
                              {
                                  Note = note,
                                  NotificationID = "ConfirmNote"
                               });

DB class:

private var db = new RetailerDb();

public class RetailerDb : DbManager
{
    public RetailerDb() : base("DBConnection")
    {
    }

    public Table<DataModel.Margin> Margin
    {
        get { return GetTable<DataModel.Margin>(); }
    }
}
  • 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-15T22:03:36+00:00Added an answer on June 15, 2026 at 10:03 pm

    So far I’ve managed to find out from the bltoolkit / Source / Data / Linq / Query.cs class:

    public static int InsertOrReplace(IDataContextInfo dataContextInfo, T obj)
    {
        ...
        else if (field.IsIdentity)
        {
            throw new LinqException("InsertOrUpdate method does not support identity field '{0}.{1}'.", sqlTable.Name, field.Name);
        }
        ...
    }
    

    The static method is called from the bltoolkit / Source / Data / Linq / Extensions.cs class:

    public static int InsertOrReplace<T>(this IDataContext dataContext, T obj)
    {
        return Query<T>.InsertOrReplace(DataContextInfo.Create(dataContext), obj);
    }
    

    It seems that Identity fields raise an exception.

    [PrimaryKey, Identity]    public int      id; //remove this field or change the column definition
    

    [EDIT]

    Take a look at how the following classes are defined:

    public class Patient
    {
        [PrimaryKey]
        public int    PersonID;
        public string Diagnosis;
    
        //more class definition
    }
    
    public class Person
    {
        //some class definition
    
        [Identity, PrimaryKey]
        //[SequenceName("PostgreSQL", "Seq")]
        [SequenceName("Firebird",   "PersonID")]
        [MapField("PersonID")] public int    ID;
                               public string FirstName { get; set; }
                               public string LastName;
        [Nullable]             public string MiddleName;
                               public Gender Gender;
    
        [MapIgnore]            public string Name { get { return FirstName + " " + LastName; }}
    
        [Association(ThisKey = "ID", OtherKey = "PersonID", CanBeNull = true)]
        public Patient Patient;
    
        //more class definition
    }
    

    And here is the sample usage in a test method:

    [Test]
    public void InsertOrUpdate1()
    {
        ForEachProvider(db =>
        {
            var id = 0;
    
            try
            {
                id = Convert.ToInt32(db.Person.InsertWithIdentity(() => new Person
                {
                    FirstName = "John",
                    LastName  = "Shepard",
                    Gender    = Gender.Male
                }));
    
                for (var i = 0; i < 3; i++)
                {
                    db.Patient.InsertOrUpdate(
                        () => new Patient
                        {
                            PersonID  = id,
                            Diagnosis = "abc",
                        },
                        p => new Patient
                        {
                            Diagnosis = (p.Diagnosis.Length + i).ToString(),
                        });
                }
    
                Assert.AreEqual("3", db.Patient.Single(p => p.PersonID == id).Diagnosis);
            }
            finally
            {
                db.Patient.Delete(p => p.PersonID == id);
                db.Person. Delete(p => p.ID       == id);
            }
        });
    }
    

    You can see that there is no usage of InsertOrUpdate for the Person class, but there is for the Patient class. So, the method is supported only when you pass in non-Identity fields.

    Note: InsertOrUpdate is obsolete but it’s still being used in the tests in the project source code. Still, it should have no impact, just think of it as InsertOrReplace.

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

Sidebar

Related Questions

Recently I start using MongoDB with Mongoose on Nodejs. When I use Model.find method
I want to start using memcache with PHP (on Ubuntu 9.10). There are lots
I'd like to start using the css :target, not() and ~ sibling selectors now.
I want to start using Cygwin, but I am not pleased with the font
Today start using the new version of Netbeans 7.1.2, I get the below notice
Could I start using CodeContracts instead of: if (XXX == Y) throw new ArgumentException(bla
Not long ago I decided to start using Nuget for managing 3rd party libraries.
I have to start using CVS at my new company so that I can
I just start using jqgrid, but when I try the most simple example (loading
I want to start using table relations in a new project. After some googling

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.