Closed solrevdev closed 1 year ago
Sounds like a binary incompatibility issue, like you're using a different version of MySqlConnector that the v2.1.8 OrmLite was built with. We haven't been regularly upgrading & testing MySqlConnector, what's the reason you're using it over the official MySql.Data ADO.NET Provider (in Ormlite.MySql)?
UPDATE
@mythz It looks like I needed it for MySqlConnectorDialect.Provider
public static IServiceCollection AddOrmLiteDbFactoryServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
{
var connectionString = configuration.GetConnectionString("defaultconnection");
if (webHostEnvironment.IsProduction())
{
services.AddSingleton<IDbConnectionFactory>(_ => new OrmLiteConnectionFactory(connectionString, MySqlConnectorDialect.Provider));
}
else
{
services.AddSingleton<IDbConnectionFactory>(_ => new OrmLiteConnectionFactory(connectionString, MySqlConnectorDialect.Provider)
{
ConnectionFilter = conn => new ProfiledDbConnection((DbConnection)conn, MiniProfiler.Current)
});
}
return services;
}
Hi @mythz good question. no good reason that I can think of. at some stage I must of (or tooling) added that in order to add the following to my .cs file
using ServiceStack.Data;
using ServiceStack.OrmLite;
Below is my full .csproj for reference.
So, should I be using a different package reference rather than <PackageReference Include="ServiceStack.Ormlite.MySqlConnector" Version="6.1.0" />
like ServiceStack.OrmLite.MySql
for example?
Do you think swapping those references out will be enough to fix.
Thanks for looking at this by the way.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<UserSecretsId>625f2771-bf7e-4716-915c-f6eb2688c4e1</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Using Include="StackExchange.Profiling" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="4.8.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="AWSSDK.S3" Version="3.7.9.67" />
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
<PackageReference Include="iTextSharp.LGPLv2.Core" Version="1.9.2" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.2.22" />
<PackageReference Include="Seq.Extensions.Logging" Version="6.1.0" />
<PackageReference Include="ServiceStack.Ormlite.MySqlConnector" Version="6.1.0" />
<PackageReference Include="solrevdev.instagrambasicdisplay" Version="1.1.3" />
<PackageReference Include="Vereyon.Web.FlashMessage" Version="3.0.0" />
<PackageReference Include="Wangkanai.Detection" Version="5.7.2" />
<PackageReference Include="ZXing.Net" Version="0.16.8" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="6.0.5.128" />
</ItemGroup>
<ItemGroup>
<Folder Include="Core/Temp/">
</Folder>
<Folder Include="Core/Resources">
</Folder>
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' == 'Debug' ">
<None Update="kestrel.pfx" CopyToOutputDirectory="PreserveNewest" Condition="Exists('kestrel.pfx')" />
</ItemGroup>
<ItemGroup>
<Content Include="Core/Resources//**/*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
That should be fine, all ServiceStack libraries need to reference the same version, if you always want to use the latest version you would use a 6.*
wildcard version instead.
Can't tell what the issue is from here, I'd recommend switching to OrmLite.MySql to see if it resolves it, if it's still an issue can you create a small standalone repro I can run locally to identify the issue.
@mythz
@mythz It looks like I needed it for MySqlConnectorDialect.Provider
which isnt in <PackageReference Include="ServiceStack.OrmLite.MySql" Version="6.4.0" />
I'm trying to just use <PackageReference Include="ServiceStack.OrmLite.MySql" Version="6.4.0" />
instead but am getting an exception that the name The name 'MySqlConnectorDialect' does not exist in the current context
I'm sure you are right and I need to switch to OrmLite.MySql I just need to try and resolve where MySqlConnectorDialect comes from. Any ideas?
public static IServiceCollection AddOrmLiteDbFactoryServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
{
var connectionString = configuration.GetConnectionString("defaultconnection");
if (webHostEnvironment.IsProduction())
{
services.AddSingleton<IDbConnectionFactory>(_ => new OrmLiteConnectionFactory(connectionString, MySqlConnectorDialect.Provider));
}
else
{
services.AddSingleton<IDbConnectionFactory>(_ => new OrmLiteConnectionFactory(connectionString, MySqlConnectorDialect.Provider)
{
ConnectionFilter = conn => new ProfiledDbConnection((DbConnection)conn, MiniProfiler.Current)
});
}
return services;
}
OrmLite.MySql uses MySqlDialect.Provider
You can find Dialect providers listed in the docs: https://docs.servicestack.net/ormlite/getting-started
@mythz
Ok same issue even with <PackageReference Include="ServiceStack.OrmLite.MySql" Version="6.4.0" />
Let me try and recreate the bug and stand up to a Github project for you. I'll post again when done...
Hi @mythz,
I will still get you a standalone repo, but I wanted to post my findings as I go along in case some ah-ha moment occurred.
The difficulty is in getting the to the right set of model/schema/variables/data to recreate the issue in a small test project.
So far I have figured out that it has something to do with Load*
methods throwing the error.
The Single*
methods seems to be fine.
The Load*
methods below throw the same exception
System.ArgumentException: Cant find 'BatchId' Property on Type 'IEnumerable`1'
at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func`2 filter) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteExecFilter.cs:line 119
However replacing them with Single*
does not
So if anything seems obvious from the below great otherwise bear with me while I try and get a repo small enough to reproduce
using var db = await DbFactory.OpenAsync().ConfigureAwait(false);
var batch = await db.SingleByIdAsync<Batch>(batchId).ConfigureAwait(false); // this actually works
var batch1 = await db.LoadSelectAsync<Batch>(x => x.Id == batchId).ConfigureAwait(false); // same error as i posted
var batch2 = await db.LoadSingleByIdAsync<Batch>(batchId).ConfigureAwait(false); // same error as i posted
The Batch
class inherits from a base BaseEntity
class and loads a collection of related Order
's. Each Order
is linked to various other classes/tables
public class BaseEntity
{
[HiddenInput]
[PrimaryKey]
public Guid Id { get; set; } = Guid.NewGuid();
[DataType(DataType.DateTime)]
[Display(Name = "Date Created")]
public DateTime DateCreated { get; set; } = DateTime.Now;
[Display(Name = "Date Modified")]
[DataType(DataType.DateTime)]
public DateTime DateModified { get; set; } = DateTime.Now;
}
public class Batch : BaseEntity
{
[AutoIncrement]
public long BatchNumber { get; set; }
[Reference, Ignore]
public IEnumerable<Order> Orders { get; set; }
}
public class Order : BaseEntity
{
public Order(Guid userId, Guid jobCardId)
{
UserId = userId;
JobCardId = jobCardId;
}
[AutoIncrement]
public long OrderNumber { get; set; }
[References(typeof(User))]
public Guid UserId { get; set; }
[References(typeof(JobCard))]
public Guid? JobCardId { get; set; }
[Ignore]
public IEnumerable<JobCardItem> JobCardItemRef { get; set; }
}
Can you change IEnumerable<T>
to List<T>
, also your data models and DTOs should have a parameterless constructor which is what the libraries use when creating & populating instances.
Can you change
IEnumerable<T>
toList<T>
, also your data models and DTOs should have a parameterless constructor which is what the libraries use when creating & populating instances.
@mythz Bingo!!!
That was indeed the issue. All is working as it should.
I changed IEnumerable<T>
to List<T>
and created a default constructor on my Order
class and all worked nicely, I can now upgrade to the latest and greatest plus I am using the correct nuget this time!
Thank you so much! 🙏
Great, happy to hear it!
Describe the issue
Hi,
I have a working released project and when I update ServiceStack.Ormlite.MySqlConnector to version 6.1.0 and above I get the following error:
Any nuget package 6.0.2 and below it works fine.
Could you point me in the right direction please.
Reproduction
The offending line that throws the exception is
Expected behavior
When I upgraded I expceted it to work or for there to be some docs or intellisense explaining that my code needed to change or something.
System Info