Rename Schemas name

Posts   
 
    
Hanjaya
User
Posts: 16
Joined: 09-Jan-2021
# Posted on: 11-Feb-2021 18:28:34   

Hi, I am a beginner with EF 6 and just testing around with it. I am using LLBLGEN pro 5.7

using (var context = new EFATKDataContext())
                {
                    var count = context.Produks.Count();
                    Console.WriteLine("Number of produks: {0}", count);
                }

from above code, i got exception : Exception: An error occurred while executing the command definition. See the inner exception for details. ---> Devart.Data.MySql.MySqlException: Table 'default.produk' doesn't exist.

I see that in the designer, the schemas name is always 'default'. This is why the query is always to default.produk which doesn't exist. the database name is 'atk' so the it should be from atk.produk.

i tried to change the schemas name but it can't. How to set so the code generated wont use schemas name. Or the schemas name is just the same as database name.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 12-Feb-2021 09:54:19   

It's the catalog name that causes this: mysql doesn't have schemas, and both the default catalog and schema name in the designer are 'default'. In the designer, in catalog explorer right click the catalog name 'Default' and select 'Rename'. Then specify the name you want it to have, e.g. atk. Save the project and regenerate the code. That should fix it.

Frans Bouma | Lead developer LLBLGen Pro
Hanjaya
User
Posts: 16
Joined: 09-Jan-2021
# Posted on: 13-Feb-2021 17:30:57   

Otis wrote:

It's the catalog name that causes this: mysql doesn't have schemas, and both the default catalog and schema name in the designer are 'default'. In the designer, in catalog explorer right click the catalog name 'Default' and select 'Rename'. Then specify the name you want it to have, e.g. atk. Save the project and regenerate the code. That should fix it.

Thanks for the answer Otis. I have tried it but it can't. Error message shown "You can't rename the default schema". i think perhaps it is because i did not run llblgen as an administrator, but after doing that, it is just the same. I can't rename the default schema.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-Feb-2021 10:14:35   

You have to rename the catalog, not the schema:

Here the catalog is sakila, in your situation it's 'Default'. You also have a 'Default' for schema under 'Schemas', you can't rename that one. Rename the top one.

Frans Bouma | Lead developer LLBLGen Pro
Hanjaya
User
Posts: 16
Joined: 09-Jan-2021
# Posted on: 14-Feb-2021 10:55:03   

Otis wrote:

You have to rename the catalog, not the schema:

Here the catalog is sakila, in your situation it's 'Default'. You also have a 'Default' for schema under 'Schemas', you can't rename that one. Rename the top one.

the catalog name is correct in the beginning. Sorry because i strikethru some of it because it's a company name. The point is the catalog name is exactly as the database name.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Feb-2021 07:30:23   

Hi Hanjaya,

I don't follow what's really the problem.

Can you explain it in a way we can reproduce it over here so we can help you better?

What is the DB and schema name in your DB, and what is in the model?

What is the problem in the generated code (you could use fake names)

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 15-Feb-2021 10:55:56   

Looking at the generated code, we think there's a bug in our EF templates that it generates the 'default' schema for Codefirst EF6, and for MySql that's not needed. We'll update the template and get back to you

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 15-Feb-2021 11:22:14   

We've fixed it, please see the 5.7.4 hotfix build we've just uploaded under my account -> 5.7 -> 5.7.4 Hotfix builds

If you're using a trial version, please open Template bindings Viewer (Tools -> Template Bindings Viewer) then select Entity Framework 6 for 'Framework', for the template bindings name select 'SD.EntityFramework.v6', and then double click the SD-EF_CodeFirst_ModelBuilder entry in the template bindings.

In the template editor at line 33, replace the modelBuilder.HasDefaultSchema("<%=defaultSchema%>");

with

<%  if(_executingGenerator.DriverID!="758A392F-06F3-498b-AED9-D85A4C795BDA")
    {
%>          modelBuilder.HasDefaultSchema("<%=defaultSchema%>");
<%  }

Press shift-ctrl-s to save it then generate code again.

Frans Bouma | Lead developer LLBLGen Pro
Hanjaya
User
Posts: 16
Joined: 09-Jan-2021
# Posted on: 15-Feb-2021 15:27:32   

Otis wrote:

We've fixed it, please see the 5.7.4 hotfix build we've just uploaded under my account -> 5.7 -> 5.7.4 Hotfix builds

If you're using a trial version, please open Template bindings Viewer (Tools -> Template Bindings Viewer) then select Entity Framework 6 for 'Framework', for the template bindings name select 'SD.EntityFramework.v6', and then double click the SD-EF_CodeFirst_ModelBuilder entry in the template bindings.

In the template editor at line 33, replace the modelBuilder.HasDefaultSchema("<%=defaultSchema%>");

with

<%  if(_executingGenerator.DriverID!="758A392F-06F3-498b-AED9-D85A4C795BDA")
    {
%>          modelBuilder.HasDefaultSchema("<%=defaultSchema%>");
<%  }

Press shift-ctrl-s to save it then generate code again.

I have download 5.7.4 hotfix. After that i uninstall llblgenpro 5.7.2 and then install 5.7.4 hotfix. After double click on SD-EF_CodeFirst_ModelBuilder entry in the template bindings, on line 33, the code is just the same as your directions.

<%  if(_executingGenerator.DriverID!="758A392F-06F3-498b-AED9-D85A4C795BDA")        // mysql doesn't support schemas. Emitting the line below gives an error... DevArt...
    {
%>          modelBuilder.HasDefaultSchema("<%=defaultSchema%>");
<%  }

So i did not change anything there. I just close the template editor, validate (F6) without error, and then F7 to generate the source code. I run the project and still the exception is there "default.produk doesn't exist"

Hanjaya
User
Posts: 16
Joined: 09-Jan-2021
# Posted on: 15-Feb-2021 15:37:17   

daelmo wrote:

Hi Hanjaya,

I don't follow what's really the problem.

Can you explain it in a way we can reproduce it over here so we can help you better?

What is the DB and schema name in your DB, and what is in the model?

What is the problem in the generated code (you could use fake names)

Hi daelmo,

the DB name is atk. The schema name in the llblgen pro designer is also atk. The generated code problem is that it always put "default" as the DB name. So the exception arise is :

Exception: An error occurred while executing the command definition. See the inner exception for details. ---> Devart.Data.MySql.MySqlException: Table 'default.produk' doesn't exist

the generated code should use atk.produk or just produk.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 16-Feb-2021 08:29:30   

Could you please try to generate the code into a new empty folder, and then make sure your application is using (referencing) the dlls from this folder?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 16-Feb-2021 10:08:41   

Indeed, the essential change to look for is in the generated <rootnamespace>ModelBuilder.cs class' public virtual void BuildModel(DbModelBuilder modelBuilder) method, at the start of that method there shouldn't be a call to HasDefaultSchema.

Frans Bouma | Lead developer LLBLGen Pro
Hanjaya
User
Posts: 16
Joined: 09-Jan-2021
# Posted on: 16-Feb-2021 15:49:45   

Otis wrote:

Indeed, the essential change to look for is in the generated <rootnamespace>ModelBuilder.cs class' public virtual void BuildModel(DbModelBuilder modelBuilder) method, at the start of that method there shouldn't be a call to HasDefaultSchema.

I just realized that you are talking about selected preset "SD.EntityFramework.v6 (Code First)" which not the one i used before (DbContext API) When you wrote like this :

If you're using a trial version, please open Template bindings Viewer (Tools -> Template Bindings Viewer) then select Entity Framework 6 for 'Framework', for the template bindings name select 'SD.EntityFramework.v6', and then double click the SD-EF_CodeFirst_ModelBuilder entry in the template bindings.

The Error is now gone because i generated the code with SD.EntityFramework.v6 (Code First) preset. Why can not i just use DbContext API preset and without previous error? from https://www.llblgen.com/Documentation/5.5/Entity%20Framework/V56/CodeFirstSupport.htm, the code first have limitations. Shouldn't that means DbContext API better than code first?

Hanjaya
User
Posts: 16
Joined: 09-Jan-2021
# Posted on: 16-Feb-2021 15:55:38   

Walaa wrote:

Could you please try to generate the code into a new empty folder, and then make sure your application is using (referencing) the dlls from this folder?

Thanks Walaa for the suggestion. Yes, after generate the source code into a new folder, try to use DbContext API and then code first preset, the error was gone.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 17-Feb-2021 08:41:35   

Hmm, we didn't assume the issue was present in the DbContext api as it uses an EDMX file which doesn't have a 'HasDefaultSchema' directive. But we'll check.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 17-Feb-2021 09:29:48   

We can't get MySQL 8 with EDMX to work with DevArt's provider, as it refuses to load the "year" type which is a valid type, even if we fix the schema issue (which is their problem btw, but as DevArt isn't the company who fixes their stuff even if it's their problem, we have to implement a workaround, as before).

However with the type problems and as EF6+EDMX is a dead end anyway, we'll mark it as not supported. Please use CodeFirst instead, if possible. I'm sorry for this, if you want to use EDMX / DbContext. If you start with a new project, I'd highly recommend using any other framework (like ours or EF Core 3.x) instead of EF6.

Frans Bouma | Lead developer LLBLGen Pro