views:

107

answers:

2

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?

+2  A: 

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?

David B
Thanks, this worked.
RJ
+1  A: 

This is weird. AddToPasswords() would be a generated method. How can a custom generated method be obsolete?

Anyway the syntax for the generic add method ( assuming db is an ObjectContext ) is:

public void InsertRecord(Password record)
{
    db.AddObject("EntitySetName", record);
}
jfar
Thanks, appreciate the answer.
RJ