开发者

Duplicate a database record with linq

开发者 https://www.devze.com 2022-12-24 10:02 出处:网络
Is there a way to duplicate a db record with linq to sql in c#? Id [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,

Is there a way to duplicate a db record with linq to sql in c#?

Id [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Foo] [nvarchar](255) NOT NULL,
[Bar] [numeric](28,12) NOT NULL,
...

Given the table above, I woul开发者_运维问答d like to duplicate a record (but give it a different id), in a way that new fields added to the DB and the Linq dbml file at a later date will still get duplicated with out having to change that code that duplicates the record.

ie I don't want to write newRecord.Foo = currentRecord.Foo; for all of the fields on the table.


I am not sure if this is what you want, but the following thread includes code using reflection and an extension method on DataContext to allow you to easily copy the members of one entity into another.

Duplicate LINQ to SQL entity / record?

0

精彩评论

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

关注公众号