Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the syntax in linq to insert a record using ObjectSet<> instead of using the .AddToXXXXX(MyEntity) as this is deprecated?

I am new to Linq to Entities and I am trying to insert a record using the linq syntax.

I have created the edmx file and instatiated it in a class with:

    PasswordEntities db = new PasswordEntities();

I have a method that looks like this:

    public void InsertRecord(Password record)
    {
        db.AddToPasswords(record);
    }

But intellisense tells me that AddToPasswords is a deprecated method and to consider using the .Add method of the associated ObjectSet property instead.

I am running VS 2010 under Framework 4.0.

What would be the syntax to do this?

like image 331
RJ. Avatar asked Dec 28 '22 14:12

RJ.


1 Answers

How about:

db.Passwords.AddObject(record);

Aside: It seems foolish to me to use the word Object in naming classes and methods in an OO world as the EF designers have done. Of course I'm adding an object, that's all we have around here. Does ObjectContext really tell me more about what the context is about than Context?

like image 185
Amy B Avatar answered Dec 31 '22 03:12

Amy B