simpleidserver / EFCore.Cassandra

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

Key may not be empty #13

Closed turowicz closed 3 years ago

turowicz commented 3 years ago

I get the following exception when trying to create a schema.

image

Context:


    public class SqlContext : DbContext
    {
        private readonly IDbConnection _connection;

        public SqlContext()
        {
        }

        public SqlContext(IDbConnection connection)
        {
            _connection = connection;
        }

        public DbSet<UnitData> Header { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                var connection = new CassandraConnectionStringBuilder();

                connection.Username = "cassandra";
                connection.Password = "cassandra";
                connection.ContactPoints = new string[] { "localhost" };

                optionsBuilder.UseCassandra(connection.ConnectionString, opt =>
                {
                    opt.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "test");
                });
            }
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.UsePropertyAccessMode(PropertyAccessMode.Property);
            builder.ForCassandraAddKeyspace("test", new KeyspaceReplicationSimpleStrategyClass(1));

            builder.Entity<UnitData>().ToTable(nameof(UnitData), "test");
            builder.Entity<UnitData>().Ignore(table => table.ETag);
            builder.Entity<UnitData>().Ignore(table => table.Timestamp);
            builder.Entity<UnitData>().Ignore(table => table.Values);
            builder.Entity<UnitData>().ForCassandraSetClusterColumns(table => new { table.RowKey });
            builder.Entity<UnitData>().HasKey(table => new
            {
                table.PartitionKey,
                table.RowKey
            });
        }
    }
turowicz commented 3 years ago

cc @simpleidserver

pluskal commented 3 years ago

I have a feeling that this is a duplicate of #10.

turowicz commented 3 years ago

@pluskal I have seen that issue and have created the keyspace manually. I am trying to create tables automatically.

simpleidserver commented 3 years ago

We couldn't reproduce your issue. Can-you use the Nuget version "2.0.3" ?

turowicz commented 3 years ago

@simpleidserver I get the same error on 2.0.3.

I have used the EF Migrations instead to sort this out. The bug is still there though.

simpleidserver commented 3 years ago

Sorry to answer you late, I was working on the CaseManagement Project. Can-you transfer your project ? I will take a closer look :)

Delta-38 commented 3 years ago

Hi, I've been seeing the same behaviour, calling EnsureCreated or EnsureCreatedAsync results in the mentioned exception. This can be verified even with the sample project when calling dbContext.Database.EnsureCreated().

turowicz commented 3 years ago

@simpleidserver the code pasted above is the project. The Program.cs only creates the context and calls EnsureCreatedAsync.

simpleidserver commented 3 years ago

The issue is fixed in the branch "release/2.0.4" :)

Delta-38 commented 3 years ago

The issue is fixed in the branch "release/2.0.4" :)

I confirm it fixed the issue on my copy of the sample and on a personal project as well.

turowicz commented 3 years ago

awesome!