Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Entity splitting incorrectly uses INNER JOIN rather LEFT JOIN

$
0
0
I added third table, and EF throws error: Invalid object name 'dbo.T3'.
C# code:
class ConsumerConfiguration : EntityTypeConfiguration<Consumer>
{
    public ConsumerConfiguration()
    {
        Property(p => p.id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
        Map(m =>
            {
                m.Properties(p => new { p.work, p.addr });
                m.ToTable("T1");
            }
        );
        Map(m =>
            {
                m.Properties(p => new { p.name, p.shipAddr });
                m.ToTable("T2");
            }
        );
        Map(m =>
            {
                m.Properties(p => new { p.salary, p.post });
                m.ToTable("T3");
            }
        );
    }
}

class Consumer
{
    public int id { get; set; }
    public string work { get; set; }
    public string addr { get; set; }
    public string name { get; set; }
    public string shipAddr { get; set; }
    public float salary { get; set; }
    public string post { get; set; }
}
T-SQL code to create tables:
create table dbo.T1
(
    id          int          not null,
    work        varchar(100) not null,
    addr        varchar(100) not null,
    constraint pk_t1 primary key (id)
);

create table dbo.T2
(
    id       int          not null,
    name     varchar(100) not null,
    shipAddr varchar(100) not null,
    constraint pk_t2 primary key (id),
    constraint fk_t2 foreign key (id) references dbo.T1(id)
    on update cascade on delete cascade
);

create table dbo.T3
(
    id     int          not null,
    salary real         not null,
    post   varchar(100) not null,
    constraint pk_t3 primary key (id),
    constraint fk_t3 foreign key (id) references dbo.T1(id)
    on update cascade on delete cascade
);

-- Some values
insert into dbo.T1 values (1, 'Work1', 'Addr1'), (2, 'Work2', 'Addr2'), (3, 'Work3', 'Addr3');
insert into dbo.T2 values (1, 'name1', 'shipAddr1'), (2, 'name2', 'shipAddr2');
insert into dbo.T3 values (1, 150.1, 'post1');
Generated SQL by EF (it's executed in SSMS perfectly):
SELECT 
    [Extent1].[id] AS [id], 
    [Extent3].[work] AS [work], 
    [Extent3].[addr] AS [addr], 
    [Extent2].[name] AS [name], 
    [Extent2].[shipAddr] AS [shipAddr], 
    [Extent1].[salary] AS [salary], 
    [Extent1].[post] AS [post]
    FROM   [dbo].[T3] AS [Extent1]
    INNER JOIN [dbo].[T2] AS [Extent2] ON [Extent1].[id] = [Extent2].[id]
    INNER JOIN [dbo].[T1] AS [Extent3] ON [Extent1].[id] = [Extent3].[id]

Viewing all articles
Browse latest Browse all 1793

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>