Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Issue: Cannot insert explicit value for identity column in table 'TABLE' when IDENTITY_INSERT is set to OF

$
0
0

Hi all,

I have issue when insert entity.

my code:

public class HsiHcm
    {
        [Required]
[Key]
public int Id { get; set; } public string AggName { get; set; } public string SrtName { get; set; } public string SrtIp { get; set; } public string SrtPw { get; set; } public string SrtPwStatus { get; set; } public string Xconnect { get; set; } public string OltName { get; set; } public int TotalSub { get; set; } public string AggName01 { get; set; } public string AggIp01 { get; set; } public string AggPw01 { get; set; } public string AggPw01Status { get; set; } public string CvName01 { get; set; } public string CvIp01 { get; set; } public string CvPw01 { get; set; } public string CvPw01Status { get; set; } public string CvSubInface01 { get; set; } public string CvName02 { get; set; } public string CvIp02 { get; set; } public string CvPw02{ get; set; } public string CvPw02Status { get; set; } public string CvSubInface02 { get; set; } public string BrasPort01 { get; set; } public string BrasPort02 { get; set; } public string Note { get; set; } public DateTime TimeUpdate { get; set; } public string UserUpdate { get; set; } public string Group { get; set; } public int Speed { get; set; } public string PortInfo { get; set; } public int poller { get; set; } public int rid { get; set; } public int iid { get; set; } public float Bw { get; set; } }
public async Task Cisco_ReadAggConf(string line, string art07, string art08, List<KeyValuePair<string, string>> srt, AggRingInfo agg, string strAgg, string AggName_)
        {
            string temp = line.Substring(line.IndexOf(" bridge group HSI_OLT"));
            string strGet = line.Substring(line.IndexOf(" bridge group HSI_OLT") + 23, temp.IndexOf("    !\n   !\n  !\n !\n") - 5);
            string[] briDomains = strGet.Split(new[] { "\n   !\n  !\n  " }, StringSplitOptions.None);
            for (int j = 0; j < briDomains.Length; j++)
            {
                string[] lineBD = briDomains[j].Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);               
                List<HsiHcm> list = new List<HsiHcm>();
                HsiHcm listHSI = new HsiHcm();
                List<KeyValuePair<string, string>> listOLT = new List<KeyValuePair<string, string>>();
                listHSI.Note = "Check Config AGG\n";
                listHSI.Group = "HSI_OLT_" + strAgg;
                listHSI.AggName = AggName_;
                for (int d = 0; d < lineBD.Length; d++)
                {
                    string row = lineBD[d].ToString();
                    if (row.Contains("bridge-domain "))
                    {
                        listHSI.Xconnect = row.Substring(row.IndexOf("bridge-domain ") + 14).Trim();
                        await _messageHubContext.Clients.All.InvokeAsync("send", row.Substring(row.IndexOf("bridge-domain ") + 14).Trim());
                    }
                    else if (row.Contains("neighbor "))
                    { 
                        if (row.Contains("10.18.255.1"))
                        {
                            listHSI.CvName01 = "HHT9403ART07";
                            listHSI.CvPw01 = row.Substring(row.IndexOf("pw-id ") + 6).Trim();
                            if (lineBD[d + 1].Contains("pw-class"))
                            {
                                listHSI.Note += "neighbor (HHT9403ART07) pw-class: OK(" + lineBD[d + 1] + ")\n";
                            }
                            else
                            {
                                listHSI.Note += "neighbor (HHT9403ART07) pw-class: NOK\n";
                            }
                        }
                        else if (row.Contains("10.18.255.2"))
                        {
                            listHSI.CvName02 = "HHT9403ART08";
                            listHSI.CvPw02 = row.Substring(row.IndexOf("pw-id ") + 6).Trim();
                            if (lineBD[d + 1].Contains("pw-class"))
                            {
                                listHSI.Note += "neighbor (HHT9403ART08) pw-class: OK(" + lineBD[d + 1] + ")\n";
                            }
                            else
                            {
                                listHSI.Note += "neighbor (HHT9403ART08) pw-class: NOK\n";
                            }
                        }
                        else if (d < lineBD.Length - 1)
                        {
                            string[] lines = row.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                            if (lineBD[d + 1].Contains("split-horizon group") && !lines[1].Contains("10.18.255."))
                            {
                                listOLT.Add(new KeyValuePair<string, string>(lines[1].Trim(), lines[3].Trim()));
                            }
                            else if (lineBD[d + 1].Contains("split-horizon group") && lines[1].Contains("10.18.255."))
                            {
                                listHSI.Note += "AGG không khai trong vfi";
                            }
                            else if (lineBD[d - 1].Contains("vfi"))
                            {
                                listHSI.AggPw01 = lines[3].Trim();
                                if (lines[1] == agg.Agg01LB0)
                                {
                                    listHSI.AggName01 = agg.AggName01;
                                }
                                else if (lines[1] == agg.Agg02LB0)
                                {
                                    listHSI.AggName01 = agg.AggName02;
                                }
                                else
                                {
                                    listHSI.AggName01 = "NOK";
                                }
                            }
                            else
                            {
                                listHSI.Note += "pw-id " + lines[3] + "khai báo NOK";
                            }
                        }
                    }
                }
                if (art07.Contains(listHSI.Xconnect))
                {
                    string tempCV07 = art07.Substring(art07.IndexOf(" xconnect group " + listHSI.Xconnect));
                    string strCV07Get = tempCV07.Substring(0, tempCV07.IndexOf("    !\n   !\n  !\n !\n"));
                    listHSI.CvSubInface01 = GetSubCV(strCV07Get);
                    listHSI.Note += "Check Config CV\n" + string.Join("\n", Cisco_CheckXConnCV(strCV07Get, agg.Agg01LB0, agg.Agg02LB0, listHSI.AggPw01));

                    string tempInfBras = art07.Substring(art07.IndexOf("interface " + listHSI.CvSubInface01.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)[0].Trim() + "\n"));
                    string strInfBrasGet = tempInfBras.Substring(0, tempInfBras.IndexOf("\n!\n"));
                    listHSI.BrasPort01 = Cisco_GetInfBra(strInfBrasGet);
                }
                if (art08.Contains(listHSI.Xconnect))
                {
                    string tempCV08 = art08.Substring(art08.IndexOf(" xconnect group " + listHSI.Xconnect));
                    string strCV08Get = tempCV08.Substring(0, tempCV08.IndexOf("    !\n   !\n  !\n !\n"));
                    listHSI.CvSubInface02 = GetSubCV(strCV08Get);
                    listHSI.Note += "Check Config CV\n" + string.Join("\n", Cisco_CheckXConnCV(strCV08Get, agg.Agg01LB0, agg.Agg02LB0, listHSI.AggPw01));

                    string tempInfBras = art08.Substring(art08.IndexOf("interface " + listHSI.CvSubInface02.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)[0].Trim() + "\n"));
                    string strInfBrasGet = tempInfBras.Substring(0, tempInfBras.IndexOf("\n!\n"));
                    if (listHSI.BrasPort01 != null)
                    {
                        listHSI.BrasPort02 = Cisco_GetInfBra(strInfBrasGet);
                    }
                    else
                    {
                        listHSI.BrasPort01 = Cisco_GetInfBra(strInfBrasGet);
                    }
                }
                try
                {
                    for (int i = 0; i < listOLT.Count; i++)
                    {
                        listHSI.SrtName = srt.Find(f => f.Key == GetLP01(listOLT[i].Key, 32)).Value;
                        listHSI.SrtIp = listOLT[i].Key;
                        listHSI.SrtPw = listOLT[i].Value;
                        OLTInfo oLT = await GetOltInfo(listHSI.SrtName);
                        if(oLT.OltName != null)
                        {
                            listHSI.OltName = oLT.OltName;
                            listHSI.poller = oLT.poller;
                            listHSI.rid = oLT.rid;
                            listHSI.iid = oLT.iid;
                            listHSI.Speed = oLT.Speed;
                            listHSI.PortInfo = oLT.PortInfo;
                            //listHSI.TotalSub = await GetTotalSubTms(oLT.OltName);
                        }                       
                        listHSI.UserUpdate = User.Identity.Name;
                        listHSI.TimeUpdate = DateTime.Now;
                        try
                        {
                            _context.tbl_HsiHcm.Add(listHSI);
                            await _context.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            _toastNotifi.AddErrorToastMessage(ex.ToString());
                        }
                    }
                }
                catch(Exception ex)
                {
                    _toastNotifi.AddErrorToastMessage(ex.ToString());
                }
            }
        }

When i use "for loop" insert data to database, then error Cannot insert explicit value for identity column in table 'TABLE' when IDENTITY_INSERT is set to OF. Column Id set Identity.

Please help me!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>