use*_*904 5 c# cassandra datastax
如何使用Datastax C#驱动程序对timeuuid数据类型的CQL查询中的"大于"或"小于"where条件?
我在Cassandra有一个表,用于存储按时间戳排序的cookie历史记录作为timeuuid:
CREATE TABLE cookie_history (
cookie_id text,
create_date timeuuid,
item_id text,
PRIMARY KEY ((cookie_id), create_date)
);
Run Code Online (Sandbox Code Playgroud)
使用C#类映射表以使用Datastax C#Cassandra驱动程序进行查询:
[Table("cookie_history")]
public class CookieHistoryDataEntry
{
[PartitionKey(1)]
[Column("cookie_id")]
public string CookieID;
[ClusteringKey(1)]
[Column("create_date")]
public Guid CreateDate;
[Column("item_id")]
public string ItemID;
}
Run Code Online (Sandbox Code Playgroud)
对于给定的cookie,我想要在给定时间戳之后的所有项目.
var myTimeUuid = new Guid("5812e74d-ba49-11e3-8d27-27303e6a4831");
var table = session.GetTable<CookieHistoryDataEntry>();
var query = table.Where(x => x.CookieID == myCookieId
&& x.CreateDate > myTimeUuid);
Run Code Online (Sandbox Code Playgroud)
但是这个(x.CreateDate> myTimeUuid)给了我一个编译时错误:
Operator '>' cannot be applied to operands of type 'System.Guid' and 'System.Guid'
Run Code Online (Sandbox Code Playgroud)
可以在原始 CQL 中对 timeuuid 使用“大于”。因此,一种解决方案是从驱动程序执行原始 CQL:
session.Execute(@"select *
from cookie_history
where cookie_id = 1242a96c-4bd4-8505-1bea-803784f80c18
and create_date > 5812e74d-ba49-11e3-8d27-27303e6a4831;");
Run Code Online (Sandbox Code Playgroud)