jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
859 stars 145 forks source link

BulkCopy Question #451

Closed jbarber2016 closed 3 years ago

jbarber2016 commented 3 years ago

Describe the question

I have a C# class defined below. My Table structure is the same IID is Primary Key Identity(1,1), but when I bulk copy multiple new items I get an error due to Primary Key Violation. What values am I supposed to have for each value when adding new entries?

Code for BulkCopy:

        public void AddVaults(List<VaultModel> models)
        {
            Database.BulkCopy<VaultModel>("dbo.Vault", models);
        }

Class:

public class VaultModel
    {
        public int IID { get; set; }
        public int System_ID { get; set; }
        public string SystemName { get; set; }
        public int Environ_ID { get; set; }
        public string EnvironName { get; set; }
        public int ValueDesc_ID { get; set; }
        public string ValueDesc { get; set; }
        public string ValueAbbrev { get; set; }
        public string Value { get; set; }
        public DateTime Eff_Date { get; set; }
        public DateTime? Exp_Date { get; set; }
        public string LastUsername { get; set; }
        public DateTime? LastDateTime { get; set; }
    }

Steps to reproduce (if applicable)

jbarber2016 commented 3 years ago

I figured it out.

I added [RecordSetId] above IID and change to private set, and works perfectly now