Anthony Tan

Anthony Tan

  • 1.9k
  • 10
  • 75

Inserting data based on my selected fields only

Oct 21 2019 1:42 AM
Dear Experts,
 
I am a newbie for ASP.NET and I have a question to seek for your advice.
 
I am creating a new record in the database & below is the code I am using now in the controller: 
  1. public ActionResult Create(TCustomer customer)  
  2.         {  
  3.             if (ModelState.IsValid)  
  4.             {  
  5.                 _CustomerRepository.NewCustomer(customer);  
  6.                 _CustomerRepository.Save();  
  7.                 return RedirectToAction("Index");  
  8.             }  
  9.             return View();  
  10.         }  
 
 here is the code in my Repo :
  1. public void NewCustomer(TCustomer customer)  
  2.        {  
  3.            _dbContext.TCustomers.Add(customer);  
  4.            Save();  
  5.        }  
 My question is, how can i save the database on the selected fields only?
 
For example, I have Customer_name, Customer_phone, customer_dob & customer_age
 
 and I just want to select Customer_name, Customer_phone to be inserted into the database. and before I save the customer_name, customer_phone I may need to find turn the data.
 
Hope you understand what i am saying and advise me.
 
Many thanks
Ant 
 
 

Answers (3)