c# - 忽略属性不起作用 CassandraCSharpDriver
问题描述
我在实体模型中使用一些属性来维护关系,我正在使用[Ignore]
从表中忽略该属性。
public class User : IdentityUser<Guid>
{
[Ignore]
public string Password { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string CommonName { get; set; }
public string ProfilePhoto { get; set; }
public bool IsDeleted { get; set; }
[Ignore]
public virtual ICollection<UserRole> UserRoles { get; set; }
}
var User = new Table<User>(dataSession);
User.CreateIfNotExists();
当我尝试使用上面的代码创建时,我得到了错误。
问题:我是否使用错误的脚本来创建表格或错误的忽略方式?
提前致谢
解决方案
检查您是否为Ignore
属性使用了正确的命名空间。Cassandra.Mapping.Attributes.Ignore
是正确的一个,而另一个已弃用。
public class Program
{
public static void Main()
{
var cluster = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
var session = cluster.Connect();
var User = new Table<User>(session, MappingConfiguration.Global, "users", "testks");
User.CreateIfNotExists();
var u = new User
{
Id = Guid.NewGuid(),
Password = "123",
FirstName = "123",
LastName = "123",
CommonName = "123",
ProfilePhoto = "321",
IsDeleted = false,
UserRoles = new List<UserRole>
{
new UserRole
{
Text = "text"
}
}
};
User.Insert(u).Execute();
var result = User.First(l => l.Id == u.Id).Execute();
Console.WriteLine(JsonConvert.SerializeObject(result));
Console.ReadLine();
User.Where(l => l.Id == u.Id).Delete().Execute();
}
}
public class User : IdentityUser<Guid>
{
[Cassandra.Mapping.Attributes.Ignore]
public string Password { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string CommonName { get; set; }
public string ProfilePhoto { get; set; }
public bool IsDeleted { get; set; }
[Cassandra.Mapping.Attributes.Ignore]
public virtual ICollection<UserRole> UserRoles { get; set; }
}
public class IdentityUser<T>
{
[Cassandra.Mapping.Attributes.PartitionKey]
public T Id { get; set; }
}
public class UserRole
{
public string Text { get; set; }
}
3.0.18
使用 C# 驱动程序对 Cassandra 运行上面的代码3.10.1
似乎可以正常工作。Password
和将UserRoles
不存在于表模式中,并且它们都将null
在使用 执行SELECT
语句时存在Linq2Cql
。
推荐阅读
- python - 中断发生后停止self.after
- amazon-web-services - How to find who created an AWS AMI?
- algorithm - How can I correct the bug in my Julia program for Lagrange Interpolation
- python - positional argument follows keyword argument graphics with dash python
- collada - FreeCAD shape.read() 错误:不支持的格式
- java - CompletionStage - thenX/thenXAsync :相同的方法签名,一个编译,另一个不编译
- c# - 比较 LINQ 中的列表并返回 2 个结果对象
- python - 在 DRF 中测试 API 端点 - 按名称访问特定的 url?
- c# - 希望轻松填充从 XSD 生成的类,其中 DataSet 具有不同的架构
- php - 无法找到类,即使自动加载器已加载文件