c# - Adding the same entity object to SQL server database -


im trying add same object table using loop job entity may required more once. tried way first saves 1 record.

                (int = 0; < required; i++)                 {                     _context.jobs.addobject(n);                 } 

then tried way thinking entity framework might not see objects being different.

                (int = 0; < required; i++)                 {                     if (i > 0)                     {                         job additionaljob = new job();                         additionaljob = n;                         _salescontext.jobs.addobject(additionaljob);                     }                     else                     {                         _context.jobs.addobject(n);                     }                 } 

the database saves on record. on appreciated.

classes reference types. ever n setting additionaljob it, same thing. classes use pointers space in memory doing making 2 pointers. when add record ef adding same data.

instead of setting n, copy properties on n.

ie,

additionaljob.name = n.name; 

or

var additonaljob = new job() { name = n.name }; 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -