I want to perform some simple queries for these below models using EF Core code first.

`Post` model

```
public class Post
{
    public int Id { get; set; }
    public string Title { get; set; }
    public string Description { get; set; }
    public int FirstTagId { get; set; }
    public FirstTag FirstTag { get; set; }
    public int SecondTagId { get; set; }
    public SecondTag SecondTag { get; set; }
}

```

`FirstTag` model

```
public class FirstTag
{
    public int Id { get; set; }
    public string tagName { get; set; }
    public ICollection<Post> Post { get; set; }
}

```

`SecondTag` model

```
public class SecondTag
{
    public int Id { get; set; }
    public string tagName { get; set; }
    public ICollection<Post> Post { get; set; }
}

```

My intention is that when I create a new post. I want to check that does the tag will be inserted into the new post exists or not using the below check operation

```
[HttpPost]
public async Task<ActionResult<Post>> CreatePost([FromBody] NewPostParam postParam)
{
    // to prevent inserting duplicate first tag
    var tag1 = _context.FirstTags.Where(x =>
        (string.IsNullOrEmpty(postParam.Post.FirstTag.tagName) || x.tagName == postParam.Post.FirstTag.tagName))
        .FirstOrDefault();
    // to prevent inserting duplicate second tag 
    var tag2 = _context.SecondTags.Where(x =>
        (string.IsNullOrEmpty(postParam.Post.SecondTag.tagName) || x.tagName == postParam.Post.SecondTag.tagName))
        .FirstOrDefault();

    if (tag1 == null)
    {
        tag1 = new FirstTag
        {
            tagName = "tag1 test",
            tagDescription = "tag1 test des!!"
        };
        _context.FirstTags.Add(tag1);
    }
    if (tag2 == null)
    {
        tag2 = new SecondTag
        {
            tagName = "tag2 test",
            tagDescription = "tag2 test des!"
        };
        _context.SecondTags.Add(tag2);
    }
     var newPost = new Post
     {
        Title = postParam.Post.Title,
        Description = postParam.Post.Description,
        FirstTag = tag1 != null ? tag1 : postParam.Post.FirstTag,
        SecondTag = tag2 != null ? tag2 : postParam.Post.SecondTag,
     };

    _context.Posts.Add(newPost);
    // remain code ...
}

```

This is the currently existing tags database

`FirstTag` table

```
Id  |  tagName
1     firstTag1
2     firstTag2

```

`SecondTag` table

```
Id  |  tagName 
1      secondTag1
2      secondTag2

```

And this is my JSON data for adding new post

```
{
    "post": {
        "title": "post2 test titlte",
        "description": "post2 test description!",
         "firstTag": {
            "tagName": "firstTag1",
            "tagDescription": "firstTag des!!"
        },
        "secondTag": {
            "tagName": "secondTag2",
            "tagDescription": "secondTag des!!"
        }
    }
}

```

I've tried several times to add the same name for `FirstTag` and `SecondTag`. But the new data is just created and the check operation I performed above maybe did nothing to prevent that. What do I do to prevent duplicate data from being inserted?