I'm testing an ASP.NET application that runs with the Entity Framework on SQL Server, and I'm having the following problem.
According to the code below, the following error is displayed: "String was not recognized as valid Boolean";
var data = DataContext.TableName
.Include("Table2")
.Include("Table2.Table3")
.Include("Table4")
.Include("Table5")
.Include("Table5.Table6")
.Include("Table7")
.Where(x => x.Id == 10)
.AsNoTracking()
.FirstOrDefault();
Versions:
.NET Framework: 4.5.2
Entity Framework: 6.2.0
MySql.Data: 8.0.11
MySql.Data.EntityFramework: 8.0.11
mySQL: 8.0
When I run the same code with the Entity Framework in SQL Server, the problem does not occur.
Does anyone know if it's a limitation of Entity Framework with mySQL?
Related
JOOQ manual states the following:
Out of the box, all jOOQ provided publishers will block on the
underlying JDBC connection, but if you provide jOOQ with a
io.r2dbc.spi.Connection or io.r2dbc.spi.ConnectionFactory, then the
publishers will execute queries in a non-blocking fashion on an R2DBC
driver.
How do I provide DSLContext with io.r2dbc.spi.Connection or io.r2dbc.spi.ConnectionFactory ?
I tried DSL.using() but it does not accept this interface.
Also - can I define the DSLContext with reactive driver through Spring Boot ?
Thank you.
How do I provide DSLContext with io.r2dbc.spi.Connection or io.r2dbc.spi.ConnectionFactory ?
At the time of this question, jOOQ 3.14 did not yet support R2DBC. With jOOQ 3.15, you can write this:
DSLContext ctx1 = DSL.using(connection);
DSLContext ctx2 = DSL.using(connectionFactory);
Just like with JDBC connections.
Also - can I define the DSLContext with reactive driver through Spring Boot ?
I suspect that this will be possible once jOOQ 3.15 is released (~ end of Q2 2021, no promises). Until then, just expose a #Bean of type DSLContext that you build manually from an injected ConnectionFactory
I am creating an MVC application with MySQL as backend. I am planning to use Entity Framework to work with this database. I already have a database so need to generate models from a database
Environment:
MySQL Server 5.7.21
MySQL for Visual Studio 1.27
Connector/NET 6.10.5
Visual Studio 2015
To Reproduce Issue:
Step 1: Add new item 'Ado.net Entity Data Model'
Step 2: Selected 'EF Designer from database' and click 'Next'
Step 3: Clicked 'New Connection'
There is no mysql connector available.
Other Details:
I already added "System. Runtime" deal as it shows error when installing Mysql. data. Ef6 from nugget
I changed "CopyLocal= true" in 'System. Data' assembly reference
I tried the same steps in Visual Studio 2017. Here I can see the provider in the step 3 but after click ok dialogue closed instead of showing table list
In Visual Studio 2015 and 17 initial time it shows the provider. when I tried next time it's not displaying
Please help. I am checking this for 2 days
To start working with VS 2013 and EF 6
Install the MySQL for Visual Studio 1.1.1
Install the Connector/Net 6.8.1 product.
To work with Database first please do the following
Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.
Add the provider to your app/web config file on the providers for Entity Framework section with the following line:
Before you run the Wizard compile your application so the new changes are applied.
To work with Model First please do the following
Add the reference for the new assembly called MySql.Data.Entity.EF6 and copy it to the bin forlder of your application.
Add the ADO.Net Entity Model new or existing.
Select the T4 template corresponding to MySQL (SSDLToMySQL)
Right click on the model and then select Generate Script to Create Database. (A MySQL script should be generated for you to create your database).
Hope this helps a bit.
MySQL for Visual Studio 1.1.1
MySQL Connector/Net 6.8.1 Beta
As MaDOS mentioned, mySql is not realy supported. If you want to use EF anyway you have to do a code-first-attempt.
You have to write the mapping-classes, and tell EF that it should NOT change the db.
Example context with disabled db-changes
public class MySqlDbContext : DbContext
{
public DbSet<MyOrderClass> Orders { get; set; }
public MySqlDbContext(IDbConnection connection)
: base((DbConnection)connection, false)
{
Database.SetInitializer<MySqlDbContext>(null); // Disable db-changes by dbContext
}
}
You main Problem are the data-types. Outside the MS-world not all data-types are supported (Oracle also got some problems with DateTime). In example-class below the "Created"-column is handled as string, which always works. In your .Net-application, you have to implement "converter"-properties which map to the desired type.
Example-Class with mapping-configuration
[Table("TORDERS")]
public class MyOrderClass
{
[Column("ORDERID")]
public long Id { get; set; }
[Column("CREATED")]
public string CreatedString { get; set; }
[NotMapped]
public DateTime? Created
{
get
{
DateTime tmp;
if (DateTime.TryParse(this.CreatedString, out tmp))
return tmp;
return null;
}
set
{
this.CreatedString = value.HasValue ? value.Value.ToString("yyyy-MM-dd HH:mm:ss") : null;
}
}
}
static void Main(params string[] args)
{
MyOrderClass tmp = new MyOrderClass() { CreatedString = "2018-01-01 11:11:11"};
Console.WriteLine(tmp.Created.ToString()); // This is how you want to work
tmp.Created = null;
Console.WriteLine(tmp.CreatedString); // this is surely not what you want to do
tmp.Created = new DateTime(2018,02,02,10,10,10);
Console.WriteLine(tmp.CreatedString); // Check if setter works ;)
}
Im not uptodate which types work, but with this you'll always be able to use EF.
We used it some time ago to access an existing db, which hat an awful db-schema anyway, because of the schema we hat to setup the datatypes anyway ;).
Could it be a 32bit vs 64bit problem?
Example: 64bit driver installed Visual studio is 32bit?
I have that problem all the time with oledb to Informix. your sofware will work perfectly in 64bit, but the tooling is 32bit.
I'm using "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final" with SQL 2008 and according to some results found on Google, I just have to add the option to .UseRowNmberForPaging() when creating a new DBcontext. This was the solution for rc1-final but it doesn't seem to work for rc2-final.
When I add the option when configuring my service, it's not recognized.
Trying to paginate records on SQL Server 2008 with EF Core so this seems to be the recommended solution.
Here is the line I'm using to Configure the service:
services.AddDbContext<Data.Models.AC_MCLContext>(options =>
options.UseSqlServer(connection).UseRowNumberForPaging());
Does anyone know how to use the row number for paging in EntityFramework Core rc2?
A solution was given to me on another forum so I thought I'd share the answer in case anyone else ran into this issue.
The API now uses a nested closure pattern so the options should be configured as a nested structure like the example below.
services.AddDbContext<Data.Models.AC_MCLContext>(options =>
options.UseSqlServer(connection,
opt => opt.UseRowNumberForPaging()));
This can also be done from the context itself.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(yourConnectionStringValue, opt=>opt.UseRowNumberForPaging());
}
2022 update: using .NET 6 + EF Core 6 + SQL Server 2008, you can install the package bellow (wich has a GitHub repository, so the code can be checked for safety).
https://www.nuget.org/packages/EntityFrameworkCore.UseRowNumberForPaging/
After installing the package, in Program.cs add:
using EntityFrameworkCore.UseRowNumberForPaging;
Then replace your DbContext service configuration:
builder.Services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString));
For:
builder.Services.AddDbContext<YourDbContext>(options => options.UseSqlServer(connectionString, o => o.UseRowNumberForPaging()));
I am new to J2EE development and its frameworks, so I'm leads to create a J2EE application usign Myeclipse,glassfish ans mysql as SGBD ... I need to create a project EJB3 session I have to use Hibernate3 ORM .. My concern is that I've worked with hibernate but in a web project type and not EJB and I really do not know how my project should be like .. I just need to understand the structure of my EJB project because normally we have 2 basic classes: EJBService and EJBserviceRemote .. EJBService, containing all my methods that I would need to call from my client (a web project for exemple) and EJBServiceRemote which contains the signature of each method .. so where do I rank the DAO classes generated by Hibernate ORM and how to call them?? shoukd I copy their code in EJBService and then declare in EJBServiceRemote to be able to call them by my client??
SOS I'm really disturbed
add all the jars that you're using in your ejb project to the following glassfish directory :
C:/..../glassfish/lib
C:/..../glassfish/domains/"your domain name"/lib
Caused by: java.lang.NoClassDefFoundError: org/hibernate/criterion/Criterion
may be you're missing one of the hibernate jars (hibernate-core.jar) or maybe you have an older version of hibernate + a recent one at the same time in your classpath.
ok everything is working now here is my methode to show data:
#SuppressWarnings("unchecked")
public int[][] afficheProduitsStockList(){
int j,a;
ProduitsStockDAO stockdao = new ProduitsStockDAO();
List<ProduitsStock> LPdt = stockdao.findAll();
a=LPdt.size();
int t[][]=new int[a][3];
Iterator it = LPdt.iterator();
while(it.hasNext()){
for(j=0;j<t.length;j++){
ProduitsStock pdt = (ProduitsStock)it.next();
t[j][0]=pdt.getCodeStock();
t[j][1]=pdt.getCodePdt();
t[j][2]=pdt.getQtePdt();
} }
return t;
}
and everything works !
Thank you all :)
I've finished building my blog using EF and Code First.
EF was running against my local SQL Express instance, with [DBO] schema.
Now i want to publish the blog, and i have done the following :
Generetade the scripts for the tables and all objects from SQL Express and change [dbo] to my [administrator] schema from my server.
Ran the scripts against the server. No issues, all objects were created an populated just fine.
I have modified Webconfig and added my BlogContext connection string to point to the server not local sql express.
Published the site.
The error i am getting is : Invalid object name 'dbo.Articles'. - where Articles is one of my entities. It resides on my sql server, [Administrator].Articles.
As far as i can tell EF still thinks im using the DBO schema. Although i have added the connection string to point to administrator user.
How can i change the schema that EF thinks it should use?
EF will use dbo schema if you didn't configure the schema explicitly through data annotations or fluent API.
[Table("MyTable", "MySchema")]
public class MyEntity
{
}
Or
modelBuidler.Entity<MyEntity>().ToTable("MyTable", "MySchema");
Just for searchers: I am just working with EF5 .NET4.5, and
[Table("MyTable", "MySchema")]
does not work. Even if VS2012 shows there is an overload which takes 2 parameters, on build it gives the error: 'System.ComponentModel.DataAnnotations.Schema.TableAttribute' does not contain a constructor that takes 2 arguments.
But the code mapping works just fine.