フロントエンドがエンティティのリストを送り返すWebAPIを作成しています。そのうちのいくつかはすでに存在している可能性があります。
public void AddTags( List<Tag> tags) //input coming from frontend js
{
foreach(Tag tag in tags){
//check if tag exists in db
//if not, create one
}
}
使用しようとしましたが、データベース内の既存のタグエンティティとDbContext.Tags.Contains(tag)
リンクする方法がわかりません。tag
私は以下のようなことをしようとしています:
Tag tag = new Tag();
tag.name = "foo";
tag.someProp1= "hello";
tag.someProp2= "world";
tag.someProp3= "123";
//tag.id = unique id is unknown, decided by db
//find an identical entity exists in db, link `tag` to it
//if no such entity exists, add to DbContext.Tags
私は次のようなものを探していDbContext.Tags.Match(tag);
ます。エンティティが与えられた場合、dbで同じものを探しています。