开发者

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

开发者 https://www.devze.com 2023-01-02 01:42 出处:网络
I am new to Linq to Entities and I am try开发者_JAVA技巧ing to insert a record using the linq syntax.

I am new to Linq to Entities and I am try开发者_JAVA技巧ing 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?


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?


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消