Search code examples
c#asp.net-core-webapiclickhouse.net-8.0

Error scaffold entity from Clickhouse DB in ASP.NET Core Web API project


I am trying to generate entity from a clickhouse database in to my ASP.NET Core 8 Web API project.

I installed these packages:

<ItemGroup>
    <PackageReference Include="ClickHouse.Client" Version="7.7.3" />
    <PackageReference Include="EFCore.ClickHouse" Version="8.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>  

I and tried like this:

dotnet ef dbcontext scaffold "Host=127.0.0.1;Port=8123;User=default;Password=;Database=db2;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4" EFCore.ClickHouse -o Models -c MyDbContext

I got this error:

Unable to find expected assembly attribute [DesignTimeProviderServices] in provider assembly 'EFCore.ClickHouse'. This attribute is required to identify the class which acts as the design-time service provider factory for the provider.

I confirm that my connection string is correct, I had successfully used this connection string to access clickhousedb from my code before.

How to scaffold entity from Clickhouse database in an ASP.NET Core Web API project?


Solution

  • You can use this package to scaffold you clickhouse database to entity

    https://github.com/denis-ivanov/EntityFrameworkCore.ClickHouse


    Follow these steps:

    1. Add necessary packages

    dotnet add package EntityFrameworkCore.ClickHouse
    dotnet add package Spectre.Console.Cli

    1. Try this

    dotnet ef dbcontext scaffold "Host=127.0.0.1;Port=8123;User=default;Password=;Database=db2;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4" EntityFrameworkCore.ClickHouse -o Models -c MyDbContext