Is there any way to ignore column of an entity from cassandra database with .net driver

Viewed 659

I am working on a .net core project and using cassandra as the data store. I need to ignore a column to store in database, i have seen in EF and in Mongo db as IgnoreBson attribute, but i am not able to find solution for cassandra with .net driver using linq. I have seen the solution for java driver but not for .net driver. I am following this link.

Thanks in advance.

2 Answers

You can define how your entities map to your columns using the MappingConfiguration. In case you need to include only specific columns use the option ExplicitColumns:

MappingConfiguration.Global.Define(
   new Map<User>()
      .TableName("users")
      .PartitionKey(u => u.UserId)
      .ExplicitColumns()
      .Column(u => u.UserId, cm => cm.WithName("id")));

https://docs.datastax.com/en/developer/csharp-driver/3.10/features/components/linq/#configuring-mappings

In case you are using attribute-based mappings, you can set ExplicitColumns on the TableAttribute:

[Table("users", ExplicitColumns = true)]
public class User
{
  // ...
}

If you want to use most of the properties in your entity, while just ignoring few of them, you can also use IgnoreAttribute:

[Table("users")]
public class User
{
  // ...

  [Ignore]
  public string IgnoreMe { get; set; }
}
Related