I have a table called tblDelegatestblDelegates
in my database which I need to populate with some data. I have created a class called Delegates which has various properties to hold the bulk of the information.
I am fairly new to c#C#, so I wanted to get the answers to a few questions as to why you should be doing things in a particular way and also to get some advice on how I could improve my code.
- Is this the correct way to do this, by first creating an instance of an object and then adding the fields to it before adding the object to the database?
- This will sound like a total noob question (so I apologies) , but why bother having to create the delegates class object, why could/should you not just add the fields directly into the database?
- In my Delegates object, should I also add the fields such as
Created_User
Created_Dttm
Updated_User
Updated_Dttm
, or am I ok leaving them out of this object like I have done below.- Is the most efficient/quickest way to do this using LINQ like I have done below, or should I be using a SQL connection, or is it just preference?
- Can anyone tell me if the formatting of my code is correct, or if I should separate out the steps into separate functions perhaps?
- Is this the correct way to do this, by first creating an instance of an object and then adding the fields to it before adding the object to the database?
- This will sound like a total noob question (so I apologies), but why bother having to create the delegates class object, why could/should you not just add the fields directly into the database?
- In my Delegates object, should I also add the fields such as
Created_User
Created_Dttm
Updated_User
Updated_Dttm
, or am I ok leaving them out of this object like I have done below. - Is the most efficient/quickest way to do this using LINQ like I have done below, or should I be using a SQL connection, or is it just preference?
- Can anyone tell me if the formatting of my code is correct, or if I should separate out the steps into separate functions perhaps?
Code to add data to database
Code to add data to database
Delegates Class
Delegates Class