I’m new to EF. I have some code that successfully inserts a record in a table. However, it uses the autogenerated “addto…” method which I understand is depreciated. I’ve seen references to using the “add” method but am having trouble. Here is the code that works:
Dim EntityContext As New DevEntities
Dim log2 As New tblLog2
log2.Error = "This is a test."
log2.Date = System.DateTime.Now
EntityContext.AddTotblLog2(log2)
EntityContext.SaveChanges()
What is the “correct” way to insert this record (vb please)?
Yes, you need to use ObjectSet<TEntity>.AddObject Method:
Basically ObjectSet.AddObject is a wrapper around the ObjectContext.AddObject method so the above call is equivalent to :
Note: I assume that
tblLog2sis the EntitySet name oftblLog2entity.