0

我有一个链接和内容,新闻实体。

**Link**: Id, Url, RowId, Discriminator
**Content**: Id, Text, Link
**News**: Id, Date, Text, Link

当我添加新内容或新闻时,我想自动将 RowId 设置为插入的 Id。这需要通过 Link.Url 更正解析实体

因此,如果我有 Link.Discriminator 和 Link.RowId,我可以肯定地通过 Id 确定我需要哪个实体(内容或新闻)。

帮我解决这个问题。

4

1 回答 1

0

As far as I understand it this should be approximately what you're after.

public void AddContent(string Text, string Link)
{
    var content = new Content {
        Text = Text,
        Link = Link
        };

    //The id is collected when you add the Entity to the context
    dbContext.SaveChanges();

    dbContext.Link.Add(new Link {
        Url = <whatever>,
        RowId = content.Id,
        Discriminator = "Content"
    });

    dbContext.SaveChanges();
}
于 2017-12-05T15:47:35.330 回答