I have the table `Project` with an enum as the primary key. When I query the table via `.Where()` on the enum column, the program crashes with the following exception:
"Unhandled exception. Cassandra.InvalidTypeException: Unknown Cassandra target type for CLR type CassandraTest.ProjectType"
A complete example is attached. Line 42 is crashing.
Is there a way to get this working other than declaring the type of `Project.ProjectType` as `int`?
windows, cassandra 4.0, docker,
Thanks for the complete example, unfortunately the LINQ expression parser does not attempt to convert the provided value to the database type (which you correctly specified as "int") so we can probably do some changes there to prevent these issues from happening.
As a workaround I suggest you to create a mapper and use the mapper for that specific request. As long as the MappingConfiguration instance is the same, the state will be reused between Table and Mapper (e.g. the prepared statement cache) so you don't have to worry about managing a singleton Mapper instance. If you're not providing a MappingConfiguration instance to the Table constructor then by default it uses a singleton shared instance (MappingConfiguration.Global) so the prepared statement cache will be reused in this scenario.
Note that the same prepared statement instance will be used ONLY if the query string passed to the Mapper matches the one generated by LINQ, which is the case with the following example (using your example as a starting point):
Thanks for the fast and thorough reply. I think I will use the following workaround as it still allows the use of LINQ and it is less stringly-typed (Of course the enum type information is still lost).
I would very much appreciate the future addition of real enum support for LINQ to the driver.
Oh I'm glad you found a workaround using LINQ. Enum support for LINQ should be added in a future release.