开发者

Entity Framework: check existence of record before inserting a new one

开发者 https://www.devze.com 2023-01-24 14:47 出处:网络
In my web app a user can assign muliple tags to products (like the tagging here on stackoverflow). There are three tables: products, tags and products_tags to implement a many to many relationship.

In my web app a user can assign muliple tags to products (like the tagging here on stackoverflow). There are three tables: products, tags and products_tags to implement a many to many relationship.

My question is, how would you implement this with the Entity Framework (LINQ to SQL): "Insert only a new tag in the tags table if it doesnt already exist there". So before the insert i have to check first if a t开发者_Go百科ag exists, whats the best way to accomplish this (best performance) ??

thanks for answers


Simple: The Tag should then be the user assigned key/PK of the entity/table.

If you have troubles synchronizing this with the database, I am sure there's something like (N)Hibernate's merge Method in EntityFramework.

0

精彩评论

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

关注公众号