Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set() should throw for owned types #14153

Closed
AndriySvyryd opened this issue Dec 12, 2018 · 0 comments
Closed

Set() should throw for owned types #14153

AndriySvyryd opened this issue Dec 12, 2018 · 0 comments
Labels
breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@AndriySvyryd
Copy link
Member

From dotnet/EntityFramework.Docs#1168 by @voroninp

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;

namespace EfCore22.OwnedTypes
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var ctx = new TestContext())
            {
                ctx.Database.EnsureCreated();
                ctx.Add(new Order { Items = { new OrderItem { Name = "Just an item." } } });
                ctx.SaveChanges();
            }

            using (var ctx = new TestContext())
            {
                var items = ctx.Set<OrderItem>().ToList();
                Console.WriteLine($"I managed to successfully get '{items.Count}' order items.");
            }

            Console.ReadKey();
        }
    }

    public class Order
    {
        public int Id { get; set; }
        public List<OrderItem> Items { get; } = new List<OrderItem>();
    }

    public class OrderItem
    {
        public string Name { get; set; }
    }

    public class TestContext : DbContext
    {
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=OwnedTypes");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Order>(b =>
            {
                b.OwnsMany(m => m.Items, ob =>
                {
                    ob.Property<int>("Id")
                        .IsRequired()
                        .ValueGeneratedOnAdd();

                    ob.HasForeignKey("OrderId");

                    ob.HasKey("Id", "OrderId");
                    ob.ToTable("OrderItems");

                });
            });
        }
    }
}
@AndriySvyryd AndriySvyryd self-assigned this Dec 12, 2018
@ajcvickers ajcvickers added this to the 3.0.0 milestone Dec 14, 2018
AndriySvyryd added a commit that referenced this issue Feb 5, 2019
Move relationship configuration to be chained after WithOwner
Throw when using HasOne/HasMany, Entity or Set for an owned type.

Fixes #12444
Fixes #9148
Fixes #14153
AndriySvyryd added a commit that referenced this issue Feb 6, 2019
Move relationship configuration to be chained after WithOwner
Throw when using HasOne/HasMany, Entity or Set for an owned type.

Fixes #12444
Fixes #9148
Fixes #14153
AndriySvyryd added a commit that referenced this issue Feb 6, 2019
Move relationship configuration to be chained after WithOwner
Throw when using HasOne/HasMany, Entity or Set for an owned type.

Fixes #12444
Fixes #9148
Fixes #14153
AndriySvyryd added a commit that referenced this issue Feb 6, 2019
Move relationship configuration to be chained after WithOwner
Throw when using HasOne/HasMany, Entity or Set for an owned type.

Fixes #12444
Fixes #9148
Fixes #14153
AndriySvyryd added a commit that referenced this issue Feb 6, 2019
Move relationship configuration to be chained after WithOwner
Throw when using HasOne/HasMany, Entity or Set for an owned type.

Fixes #12444
Fixes #9148
Fixes #14153
AndriySvyryd added a commit that referenced this issue Feb 7, 2019
Move relationship configuration to be chained after WithOwner
Throw when using HasOne/HasMany, Entity or Set for an owned type.

Fixes #12444
Fixes #9148
Fixes #14153
@AndriySvyryd AndriySvyryd reopened this Feb 7, 2019
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Feb 7, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview3 Feb 22, 2019
@AndriySvyryd AndriySvyryd removed their assignment Feb 28, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview3, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

2 participants