simpleidserver / EFCore.Cassandra

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

How to Configure tables (Single navigation property) #17

Closed best0032001 closed 3 years ago

best0032001 commented 3 years ago

I read document in https://efcorecassandra.readthedocs.io/en/latest/intro/getting-started-with-efcorecassandra.html#configure-tables

Then example in Document I found this modelBuilder.Entity<Applicant>() .ToTable("applicants", "cv") .HasKey(p => new { p.Id, p.LastName }); modelBuilder.Entity<Applicant>() .ForCassandraSetClusterColumns(s => new { s.LastName });

I want to Design Model type Single navigation property like this

public class Blog { public int BlogId { get; set; } public string Url { get; set; }

public List<Post> Posts { get; set; }

} public class Post { public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } } this referrance https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key

How to Configure tables Just like this in EFCore.Cassandra v 2.0.3

simpleidserver commented 3 years ago

Hi,

In cassandra you cannot define foreign key because it's not a relational database, the website https://docs.datastax.com/en/cql-oss/3.3/cql/ddl/dataModelingApproach.html explains how to model your database.

I'm going to make some modifications on the project to support "list<frozen>" & join a sample project to explain how to store a list of "post" as a list of user defined types.

simpleidserver commented 3 years ago

The sample project has been updated in the branch "origin/release/2.0.5" : https://github.com/simpleidserver/EFCore.Cassandra/tree/release/2.0.5/samples/EFCore.Cassandra.Samples.

The application can have one or more phones (a phone is defined as a UDT / User Defined Type).

In the configuration, there is a new UDT:

modelBuilder.Entity<ApplicantPhone>()
.ToUserDefinedType("applicant_phone")
.HasNoKey();

A new navigation property "public ApplicantPhone[] Phones { get; set; }" has been added into the "Applicant".