locked
How to add record in two table from one view at same time RRS feed

  • Question

  • User-2035378889 posted

    Dear's fellows due to a new in asp.net mvc  am have problem with adding record in tow table at a time form one view

    this is my supplier model

    using PharmaApp.Core.DataModel.Base;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PharmaApp.Core.DataModel
    {
        [Table("Supplier")]
        public class SupplierModel : BaseModel
        {
            [Required]
            public string  Name { get; set; }        
            public string Email { get; set; }
            public string TrialCategory { get; set; }
            public string AccountType { get; set; }
            public string AccountSubType { get; set; }
            public string PartyType { get; set; }
            public string ItemType { get; set; }
            public string Drcr { get; set; }
            public new string Company { get; set; }
            public int Bf { get; set; }
            public DateTime BFDate { get; set; }       
            public string Phone { get; set; }
            public string Address { get; set; }
            public string Notes { get; set; }
           

        }
    }

    This is my 2 model 

    using PharmaApp.Core.DataModel.Base;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PharmaApp.Core.DataModel
    {
        [Table("Ledger")]
        public class LedgersModel : BaseModel
        {


            [DisplayName("AccountsName")]
            [ForeignKey("SupplierModel")]
            public Nullable<int> AcId { get; set; }
            public SupplierModel SupplierModel { get; set; }
            public Nullable<int> EntryId { get; set; }
            public Nullable<DateTime> EntryDate { get; set; }
            public Nullable<int> BillNo { get; set; }
            public string Deacripation { get; set; }
            public Nullable<int> DrAmount { get; set; }
            public Nullable<int> CrAmount { get; set; }
          
            public string Sp { get; set; }

            public string UserName { get; set; }
        }
    }

    And This is my View

    @model PharmaApp.Core.DataModel.SupplierModel
    @{
        ViewBag.Title = "Add New Account";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker3.css" rel="stylesheet" />
    <div class="wraper container-fluid">
        <div class="page-title">
            <h3 class="title">Chart Of Account </h3>
        </div>
        <div class="row">
            <div class="col-lg-10 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">New Account</h3>
                    </div>
                    <div class="panel-body">
                        @using (Html.BeginForm("AddSupplier", "Admin", FormMethod.Post))
                        {
                            @Html.AntiForgeryToken()
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="AccountType"> Account Name: </label>
                                    @Html.TextBoxFor(x => x.Name, null, new { @class = "form-control", @placeholder = "Enter Name " })
                                    @Html.ValidationMessageFor(x => x.Name, "", new { @class = "text-danger" })
                                </div>
                            </div>

                            <div class="form-group col-md-4">
                                <label for="AccountType"> Account Type: </label>
                                @Html.DropDownList("AccountType", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Assets", Value="Assets"},
                                        new SelectListItem() {Text = "Liabilities", Value="Liabilities"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <label for="AccountSubType"> Account Sub Type: </label>
                                   @Html.DropDownList("AccountSubType", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Current Assets", Value="Current Assets"},
                                        new SelectListItem() {Text = "Accounts Receivable", Value="Accounts Receivable"},
                                         new SelectListItem() {Text = "Other Current Assets", Value="Other Current Assets"},
                                          new SelectListItem() {Text = "Inventory", Value="Inventory"},
                                           new SelectListItem() {Text = "Cash", Value="Cash"},
                                            new SelectListItem() {Text = "Fixed Assets", Value="Fixed Assets"},
                                             new SelectListItem() {Text = "Current Liabilities", Value="Current Liabilities"},
                                              new SelectListItem() {Text = "Accounts Payable", Value="Accounts Payable"},
                                                new SelectListItem() {Text = "Other Current Liabilities", Value="Other Current Liabilities"},
                                                new SelectListItem() {Text = " Payroll Liabilities", Value=" Payroll Liabilities"},
                                                new SelectListItem() {Text = "Long Term Liabilities", Value="Long Term Liabilities"},
                                                new SelectListItem() {Text = "Equity", Value="Equity"}
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <label for="AccountType"> Category: </label>
                                @Html.DropDownList("TrialCategory", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Party", Value="Party"},
                                        new SelectListItem() {Text = "Bank", Value="Bank"},
                                         new SelectListItem() {Text = "Item", Value="Item"},
                                          new SelectListItem() {Text = "Cash", Value="Cash"},
                                          new SelectListItem() {Text = "Assets", Value="Assets"},
                                           new SelectListItem() {Text = "Expenses", Value="Expenses"},
                                           new SelectListItem() {Text = "Income", Value="Income"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    <label for="Date">Party Type  : </label>
                                    @Html.TextBoxFor(x => x.PartyType, null, new { @class = "form-control", @placeholder = "Part Type " })
                                    @Html.ValidationMessageFor(x => x.PartyType, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.ItemType)
                                    @Html.TextBoxFor(x => x.ItemType, null, new { @class = "form-control", @placeholder = "Item Type " })
                                    @Html.ValidationMessageFor(x => x.ItemType, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="form-group col-md-4">
                                    @Html.LabelFor(x => x.Phone)
                                    @Html.TextBoxFor(x => x.Phone, null, new { @class = "form-control", @placeholder = "Enter Phone Number " })
                                    @Html.ValidationMessageFor(x => x.Phone, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Email)
                                    @Html.TextBoxFor(x => x.Email, null, new { @class = "form-control", @placeholder = "Enter Email " })
                                    @Html.ValidationMessageFor(x => x.Email, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Address)
                                    @Html.TextAreaFor(x => x.Address, new { @class = "form-control", @rows = "3", @placeholder = "Address" })
                                    @Html.ValidationMessageFor(x => x.Address, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="Date">BF Date  : </label>
                                    @Html.TextBox("Bfdate", null, new { @class = "form-control mydatepicker", @placeholder = "Select BF Date ", onchange = "blankme(this.id)" })
                                    @Html.ValidationMessageFor(x => x.BFDate, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Bf)
                                    @Html.TextBoxFor(x => x.Bf, null, new { @class = "form-control", @placeholder = "Amount " })
                                    @Html.ValidationMessageFor(x => x.Bf, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <label for="Drcr"> Dr/Cr: </label>
                                @Html.DropDownList("Drcr", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Dr", Value="Dr"},
                                        new SelectListItem() {Text = "Cr", Value="Cr"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                <small id="error_Payment" class="form-text error_msg">Select Dr/Cr</small>
                            </div>

                            <button type="submit" class="btn btn-purple">
                                Submit
                            </button>
                        }
                    </div>
                </div>
            </div>

        </div>
    </div>
    @section scripts {
        <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.js"></script>

        @Scripts.Render("~/bundles/App")
    }

    I wnat to add ID,Bfdate from supplier to ledger

    in  AcId,EntryDate

    please help me

    Friday, April 16, 2021 7:43 PM

All replies

  • User475983607 posted

    ABDULLAH ANOTECH

    Dear's fellows due to a new in asp.net mvc

    You should take the time to go through a few beginning level tutorials to learn the basics.  Also, please use the "Insert/edit code sample" when sharing code.

    ABDULLAH ANOTECH

    am have problem with adding record in tow table at a time form one view

    What is the problem?  Are you receiving an error?  If so, what is the error?  

    ABDULLAH ANOTECH

    I wnat to add ID,Bfdate from supplier to ledger

    in  AcId,EntryDate

    The code shown populates one model.  Can you share the code that populates the other model? Can you explain the troubleshooting steps you have performed?  

    Friday, April 16, 2021 7:53 PM
  • User-2035378889 posted

    Thanks for responding Dear Sir

    I put below controller

     [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult AddSupplier(SupplierModel model)
            {
                if (ModelState.IsValid)
                {
                    _supplierRepository.Insert(model);
                     using (var context = new PharmaDbContext())
                {
                    context.Suppliers.Add(model);
                    var itemRow = context.Ledgers.FirstOrDefault(o => o.AcId == model.Id);
                    if (itemRow != null)
                    {
                        itemRow.AcId = model.Id; itemRow.IsDelete = model.IsDelete; itemRow.EntryDate=model.BFDate;
                        context.Entry(itemRow).State = EntityState.Modified;
                    }
                    else
                    {
                        context.Ledgers.Add(new LedgersModel() { AcId = model.Id, EntryDate  = model.BFDate,IsDelete=model.IsDelete});
                    }
                    context.SaveChanges();
                }
                    return RedirectToAction("SupplierList");
                }
                return View(model);
            }

    But  this is showing me errror

    Procedure or function InsertLedgers has too many arguments specified.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: Procedure or function InsertLedgers has too many arguments specified.

    Source Error:

    Line 290:                    context.Ledgers.Add(new LedgersModel() { AcId = model.Id, EntryDate  = model.BFDate,IsDelete=model.IsDelete});
    Line 291:                }
    Line 292:                context.SaveChanges();
    Line 293:            }
    Line 294:                return RedirectToAction("SupplierList");
    Friday, April 16, 2021 11:34 PM
  • User475983607 posted

    The error indicates the code tries to create more SQL parameter than the defined by a stored procedure or function.   I'm guessing the error has to do with the use of inheritance but I'm not sure.

    [Table("Ledger")]
    public class LedgersModel : BaseModel

    There should not be a  DbContext and repository in the same context.  Are you writing to two different databases?   

    Saturday, April 17, 2021 10:24 AM
  • User-2035378889 posted

    Thank u so much sir 
    last night I changed my Controller with

     public ActionResult AddSupplier(SupplierModel model)
            {
                if (ModelState.IsValid)
                {
                    _supplierRepository.Insert(model);
                     using (var context = new PharmaDbContext())
                {
                   
                    var itemRow = context.Ledgers.FirstOrDefault(o => o.AcId == model.Id);
                 
                      _ledgerRepository.Insert(new LedgersModel { AcId = model.Id ,EntryDate = model.BFDate, IsDelete = model.IsDelete});
                    }
                
                
                    return RedirectToAction("SupplierList");
                }
                return View(model);

    System.NullReferenceException: 'Object reference not set to an instance of an object.'

    Mgehard sir sorry am totally new in mvc  I switched from vb.net to asp.net mvc

    Saturday, April 17, 2021 9:17 PM
  • User-2035378889 posted

    I want to add record in two tables at time

    this is my First Table

    using PharmaApp.Core.DataModel.Base;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PharmaApp.Core.DataModel
    {
        [Table("Supplier")]
        public class SupplierModel : BaseModel
        {
            [Required]
            public string  Name { get; set; }        
            public string Email { get; set; }
            public string TrialCategory { get; set; }
            public string AccountType { get; set; }
            public string AccountSubType { get; set; }
            public string PartyType { get; set; }
            public string ItemType { get; set; }
            public string Drcr { get; set; }
            public new string Company { get; set; }
            public int Bf { get; set; }
            public DateTime BFDate { get; set; }       
            public string Phone { get; set; }
            public string Address { get; set; }
            public string Notes { get; set; }

            public ICollection<SupplierModel> Items { get; set; }

            public SupplierModel()
            {
                Items = new List<SupplierModel>();
            }
        }
    }

    and this is my 2nd table

    using PharmaApp.Core.DataModel.Base;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PharmaApp.Core.DataModel
    {
        [Table("Ledger")]
        public class LedgersModel : BaseModel
        {


            [DisplayName("AccountsName")]
            [ForeignKey("SupplierModel")]
            public Nullable<int> AcId { get; set; }
            public SupplierModel SupplierModel { get; set; }
            public Nullable<int> EntryId { get; set; }
            public Nullable<DateTime> EntryDate { get; set; }
            public Nullable<int> BillNo { get; set; }
            public string Deacripation { get; set; }
            public Nullable<int> DrAmount { get; set; }
            public Nullable<int> CrAmount { get; set; }
          
            public string Sp { get; set; }

            public string UserName { get; set; }
           
        }
    }

    and this is my View

    @model PharmaApp.Core.DataModel.SupplierModel
    @{
        ViewBag.Title = "Add New Account";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker3.css" rel="stylesheet" />
    <div class="wraper container-fluid">
        <div class="page-title">
            <h3 class="title">Chart Of Account </h3>
        </div>
        <div class="row">
            <div class="col-lg-10 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">New Account</h3>
                    </div>
                    <div class="panel-body">
                        @using (Html.BeginForm("AddSupplier", "Admin", FormMethod.Post))
                        {
                            @Html.AntiForgeryToken()
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="AccountType"> Account Name: </label>
                                    @Html.TextBoxFor(x => x.Name, null, new { @class = "form-control", @placeholder = "Enter Name " })
                                    @Html.ValidationMessageFor(x => x.Name, "", new { @class = "text-danger" })
                                </div>
                            </div>

                            <div class="form-group col-md-4">
                                <label for="AccountType"> Account Type: </label>
                                @Html.DropDownList("AccountType", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Assets", Value="Assets"},
                                        new SelectListItem() {Text = "Liabilities", Value="Liabilities"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <label for="AccountSubType"> Account Sub Type: </label>
                                   @Html.DropDownList("AccountSubType", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Current Assets", Value="Current Assets"},
                                        new SelectListItem() {Text = "Accounts Receivable", Value="Accounts Receivable"},
                                         new SelectListItem() {Text = "Other Current Assets", Value="Other Current Assets"},
                                          new SelectListItem() {Text = "Inventory", Value="Inventory"},
                                           new SelectListItem() {Text = "Cash", Value="Cash"},
                                            new SelectListItem() {Text = "Fixed Assets", Value="Fixed Assets"},
                                             new SelectListItem() {Text = "Current Liabilities", Value="Current Liabilities"},
                                              new SelectListItem() {Text = "Accounts Payable", Value="Accounts Payable"},
                                                new SelectListItem() {Text = "Other Current Liabilities", Value="Other Current Liabilities"},
                                                new SelectListItem() {Text = " Payroll Liabilities", Value=" Payroll Liabilities"},
                                                new SelectListItem() {Text = "Long Term Liabilities", Value="Long Term Liabilities"},
                                                new SelectListItem() {Text = "Equity", Value="Equity"}
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <label for="AccountType"> Category: </label>
                                @Html.DropDownList("TrialCategory", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Party", Value="Party"},
                                        new SelectListItem() {Text = "Bank", Value="Bank"},
                                         new SelectListItem() {Text = "Item", Value="Item"},
                                          new SelectListItem() {Text = "Cash", Value="Cash"},
                                          new SelectListItem() {Text = "Assets", Value="Assets"},
                                           new SelectListItem() {Text = "Expenses", Value="Expenses"},
                                           new SelectListItem() {Text = "Income", Value="Income"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                @Html.ValidationMessageFor(x => x.AccountType, "", new { @class = "text-danger" })
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    <label for="Date">Party Type  : </label>
                                    @Html.TextBoxFor(x => x.PartyType, null, new { @class = "form-control", @placeholder = "Part Type " })
                                    @Html.ValidationMessageFor(x => x.PartyType, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.ItemType)
                                    @Html.TextBoxFor(x => x.ItemType, null, new { @class = "form-control", @placeholder = "Item Type " })
                                    @Html.ValidationMessageFor(x => x.ItemType, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="form-group col-md-4">
                                    @Html.LabelFor(x => x.Phone)
                                    @Html.TextBoxFor(x => x.Phone, null, new { @class = "form-control", @placeholder = "Enter Phone Number " })
                                    @Html.ValidationMessageFor(x => x.Phone, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Email)
                                    @Html.TextBoxFor(x => x.Email, null, new { @class = "form-control", @placeholder = "Enter Email " })
                                    @Html.ValidationMessageFor(x => x.Email, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Address)
                                    @Html.TextAreaFor(x => x.Address, new { @class = "form-control", @rows = "3", @placeholder = "Address" })
                                    @Html.ValidationMessageFor(x => x.Address, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="Date">BF Date  : </label>
                                    @Html.TextBox("Bfdate", null, new { @class = "form-control mydatepicker", @placeholder = "Select BF Date ", onchange = "blankme(this.id)" })
                                    @Html.ValidationMessageFor(x => x.BFDate, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <div class="form-group">
                                    @Html.LabelFor(x => x.Bf)
                                    @Html.TextBoxFor(x => x.Bf, null, new { @class = "form-control", @placeholder = "Amount " })
                                    @Html.ValidationMessageFor(x => x.Bf, "", new { @class = "text-danger" })
                                </div>
                            </div>
                            <div class="form-group col-md-4">
                                <label for="Drcr"> Dr/Cr: </label>
                                @Html.DropDownList("Drcr", new List<SelectListItem>
                                    {
                                        new SelectListItem() {Text = "Dr", Value="Dr"},
                                        new SelectListItem() {Text = "Cr", Value="Cr"},
                                    },  new { @class = "form-control", onchange = "blankme(this.id)" })

                                <small id="error_Payment" class="form-text error_msg">Select Dr/Cr</small>
                            </div>

                            <button type="submit" class="btn btn-purple">
                                Submit
                            </button>
                        }
                    </div>
                </div>
            </div>

        </div>
    </div>
    @section scripts {
        <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.js"></script>

        @Scripts.Render("~/bundles/App")
    }

    and this is my Controller

    [HttpPost]
            [ValidateAntiForgeryToken]
            public ActionResult AddSupplier(SupplierModel model)
            {
                if (ModelState.IsValid)
                {
                    _supplierRepository.Insert(model);

                    foreach (var item in model.Items)
                    {
                        var stock = _ledgerRepository.All().SingleOrDefault(x => x.AcId == item.Id);
                        if (stock != null)
                        {
                            
                        }
                        else
                        {   // add new stock
                            _ledgerRepository.Insert(new LedgersModel { AcId = item.Id, EntryDate = item.BFDate, IsDelete = item.IsDelete });
                        }
                    }


                    //return RedirectToAction("SupplierList");
                }
                    return View(model);
                
            }

    when I submit only supplier record inserted and 

    hope some one guide me

    thanks

    Saturday, April 17, 2021 11:16 PM
  • User475983607 posted

    System.NullReferenceException: 'Object reference not set to an instance of an object.'

    Mgehard sir sorry am totally new in mvc  I switched from vb.net to asp.net mvc

    The null exception shows the line of code that caused the exception.   I recommend doing basic troubleshooting.  Set a break point and find the null item.  Once you know what is null then you can should be able to fix the problem.  This is no different than debugging VB.NET.

    Sunday, April 18, 2021 9:29 AM
  • User-939850651 posted

    Hi ABDULLAH ANOTECH,

    when I submit only supplier record inserted

    Based on the code you provided, I am confused about the code at Yellow part:

    foreach (var item in model.Items)
    {
      var stock = _ledgerRepository.All().SingleOrDefault(x => x.AcId == item.Id);
      if (stock != null)
      {
      }
      else
      {   
    // add new stock _ledgerRepository.Insert(new LedgersModel { AcId = item.Id, EntryDate = item.BFDate, IsDelete = item.IsDelete }); }
    }

    Enumerable.All() is used to judge whether all the elements of the collection meet a certain condition, and return the bool value as the result.

    It cannot be used with SingleOrDefault() at the same time, you should be able to see red lines (error mark )under this part of the code.

    According to your requirements, you should want to check whether the record is already in the database (using Acid as the query condition), so just use SingleOrDefault() can achieve your purpose.

    If I misunderstood anyting, could you provide more details?

    Best regards,

    Xudong Peng

    Monday, April 19, 2021 6:19 AM