Page 1 of 1

Name conflict: when table name is the same name as the project namespace

Posted: Tue 14 Nov 2017 00:35
by RobertK
Example
Project Name: Company.Account.API
Context Namespace: Company.Account.API.Data
Default Namespace: Company.Account.API.DataModels

Table Name: Account


Error message in "ApplicationDbContext.cs" "Account" is a namespace but used like a type

Code: Select all

namespace Company.Account.API.Data
{
        public virtual DbSet<Account> Accounts { get; set; }
}

Workaround: You must manually edit and update each file to fix the issue.

Change name from "Account" to "Account.API.DataModels.Account"
Example
1)
From

Code: Select all

public virtual DbSet<Account> Accounts { get; set; }
To

Code: Select all

public virtual DbSet<Account.API.DataModels.Account> Accounts { get; set; }

2)
From

Code: Select all

        #region Account Navigation properties
            modelBuilder.Entity<Account>().HasOne(x => x.AccountType).WithMany(op => op.Accounts).IsRequired(true).HasForeignKey(@"AccountTypeId");
        #endregion
To

Code: Select all

        #region Account Navigation properties
            modelBuilder.Entity<Account.API.DataModels.Account>().HasOne(x => x.AccountType).WithMany(op => op.Accounts).IsRequired(true).HasForeignKey(@"AccountTypeId");
        #endregion

Re: Name conflict: when table name is the same name as the project namespace

Posted: Thu 16 Nov 2017 10:17
by RobertK
Anyone know how to fix this issue without manually having to edit the generated code?

Re: Name conflict: when table name is the same name as the project namespace

Posted: Thu 16 Nov 2017 20:29
by Shalex
We have reproduced the issue and are investigating it.

Re: Name conflict: when table name is the same name as the project namespace

Posted: Mon 20 Nov 2017 03:42
by RobertK
Shalex wrote:We have reproduced the issue and are investigating it.
Thanks!

A simple fix is to allow adding an option to generate full names either for all models or just conflict names? (check is the project name the same as the model name? if true generate full name)

Re: Name conflict: when table name is the same name as the project namespace

Posted: Mon 20 Nov 2017 10:49
by Shalex
The issue is fixed. Look forward to the next public build of Entity Developer.

Re: Name conflict: when table name is the same name as the project namespace

Posted: Fri 24 Nov 2017 08:57
by Shalex
The new (6.2.384) build of Entity Developer is available for download.