예제 #1
0
    public void Identity_conflict_throws_for_owned_composite_primary_key()
    {
        using var context = new IdentityConflictContext();
        context.Attach(
            new CompositeKey
        {
            Id1          = 77,
            Id2          = 78,
            AlternateId1 = 66,
            AlternateId2 = 67,
            Owned        = new CompositeKeyOwned()
        });

        var duplicateOwned = new CompositeKeyOwned();

        context.Entry(duplicateOwned).Property("CompositeKeyId1").CurrentValue = 77;
        context.Entry(duplicateOwned).Property("CompositeKeyId2").CurrentValue = 78;

        Assert.Equal(
            CoreStrings.IdentityConflictOwned("CompositeKeyOwned", "{'CompositeKeyId1', 'CompositeKeyId2'}"),
            Assert.Throws <InvalidOperationException>(
                () => context.Attach(
                    new CompositeKey
        {
            Id1          = 177,
            Id2          = 178,
            AlternateId1 = 166,
            AlternateId2 = 168,
            Owned        = duplicateOwned
        })).Message);
    }
예제 #2
0
    public void Identity_conflict_throws_for_owned_primary_key()
    {
        using var context = new IdentityConflictContext();
        context.Attach(
            new SingleKey
        {
            Id          = 77,
            AlternateId = 66,
            Owned       = new SingleKeyOwned()
        });

        var duplicateOwned = new SingleKeyOwned();

        context.Entry(duplicateOwned).Property("SingleKeyId").CurrentValue = 77;

        Assert.Equal(
            CoreStrings.IdentityConflictOwned("SingleKeyOwned", "{'SingleKeyId'}"),
            Assert.Throws <InvalidOperationException>(
                () => context.Attach(
                    new SingleKey
        {
            Id          = 78,
            AlternateId = 67,
            Owned       = duplicateOwned
        })).Message);
    }