simpleidserver / EFCore.Cassandra

Entity Framework Core provider for Cassandra
Apache License 2.0
35 stars 16 forks source link

Net 5 support #6

Closed datdefboi closed 4 years ago

datdefboi commented 4 years ago
public class Storage : DbContext
    {
        private DbSet<Car> Cars { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseCassandra("Contact Points=127.0.0.1;",
                opt => { opt.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "cl"); });
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ForCassandraAddKeyspace("hl", new KeyspaceReplicationSimpleStrategyClass(2));
            modelBuilder.Entity<Car>().ToTable("Cars", "hl").HasKey(p => p.ID);
            modelBuilder.Entity<Car>().ForCassandraSetClusterColumns(p => p.ID);
        }
    }
class Program: IDesignTimeDbContextFactory<Storage>
    {
        static void Main(string[] args)
        {
        }

        public Storage CreateDbContext(string[] args)
        {
            return new Storage();
        }
    }
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <Configurations>Debug;Release;</Configurations>
    <Platforms>AnyCPU;x64</Platforms>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="CassandraCSharpDriver" Version="3.15.0" />
    <PackageReference Include="cntk.gpu" Version="2.7.0" />
    <PackageReference Include="EFCore.Cassandra" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-preview.5.20278.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-preview.5.20278.2" />
  </ItemGroup>

</Project>

this config throws the same error when dotnet ef migrations add Initial

Build started...
Build succeeded.
System.TypeLoadException: Method 'Create' in type 'Microsoft.EntityFrameworkCor
e.Cassandra.Query.Sql.Internal.CassandraSqlTranslatingExpressionVisitorFactory'
 from assembly 'EFCore.Cassandra, Version=2.0.0.0, Culture=neutral, PublicKeyTo
ken=null' does not have an implementation.
   at Microsoft.Extensions.DependencyInjection.CassandraServiceCollectionExtens
ions.AddEntityFrameworkCassandra(IServiceCollection serviceCollection)
   at Microsoft.EntityFrameworkCore.Cassandra.Infrastructure.Internal.Cassandra
OptionsExtension.ApplyServices(IServiceCollection services)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices
(IDbContextOptions options, ServiceCollection services)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayC
lass4_0.<GetOrAdd>g__BuildServiceProvider|3()
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayC
lass4_0.<GetOrAdd>b__2(Int64 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, F
unc`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbC
ontextOptions options, Boolean providerRequired)
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Inf
rastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
   at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExten
sions.GetService[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetServic
e[TService](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateC
ontext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateC
ontext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMig
ration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(S
tring name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__
DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c_
_DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Exec
ute(Action action)
Method 'Create' in type 'Microsoft.EntityFrameworkCore.Cassandra.Query.Sql.Inte
rnal.CassandraSqlTranslatingExpressionVisitorFactory' from assembly 'EFCore.Cas
sandra, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an
 implementation.
simpleidserver commented 4 years ago

Can-you remove the dependencies with Microsoft.EntityFrameworkCore & Microsoft.EntityFrameworkCore.Design and execute the command dotnet ef migrations add Initial again ?

datdefboi commented 4 years ago

I've made an example of a bad driver's work. Feel free to some PRs and discussions. https://github.com/datdefboi/CassandraEFExample The DB has no changes and keyspaces (just deployed)

thabart commented 4 years ago

I made a pull request on your project

datdefboi commented 4 years ago

I've updated my example. A migration creates successfully, but it throws some exceptions:

Build started...
Build succeeded.
Failed executing DbCommand (21ms) [Parameters=[], CommandType='Text', CommandTimeout='-1']
SELECT count(*) FROM system_schema.tables WHERE keyspace_name='' and table_name='__EFMigrationsHistory'
Cassandra.InvalidQueryException: Key may not be empty
   at Cassandra.Tasks.TaskHelper.WaitToComplete(Task task, Int32 timeout)
   at Cassandra.Tasks.TaskHelper.WaitToCompleteWithMetrics(IMetricsManager manager, Task task, Int32 timeout)
   at Cassandra.Tasks.TaskHelper.WaitToCompleteWithMetrics[T](IMetricsManager manager, Task`1 task, Int32 timeout)
   at Cassandra.Session.Execute(IStatement statement, String executionProfileName)
   at Cassandra.Session.Execute(IStatement statement)
   at Cassandra.Session.Execute(String cqlQuery, ConsistencyLevel consistency)
   at Cassandra.Data.CqlCommand.ExecuteScalar()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteScalar(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Cassandra.Migrations.CassandraHistoryRepository.Exists()
   at Microsoft.EntityFrameworkCore.Cassandra.Migrations.Internal.CassandraMigrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Key may not be empty
datdefboi commented 4 years ago

Have you tried to run my sample project and check the success migrations add and database update commands execution?

simpleidserver commented 4 years ago

I made an another pull request to fix the migration. Sorry for the inconvenience.