Cassandra:C#中的UDT POCO列表

时间:2016-04-15 14:31:13

标签: c# dictionary cassandra

我需要你的帮助...

我正在使用Cassandra数据库和DataStax驱动程序为C#开发一个解决方案来生成POCO代码以生成数据库的列系列,问题在于我想要映射列的那个是一个UDT字典,并没有运行,在代码下面,以便有人可以帮助我...

Maps.cs

For<Users>()
            .TableName("Users")
            .PartitionKey(key => key.UsersId)
            .Column(u => u.UsersId, map => map.WithName("UsersId"))
            .Column(u => u.ImgProfileUrl, map => map.WithName("ImgProfileUrl"))
            .Column(u => u.Name, map => map.WithName("Name"))
            .Column(u => u.Gender, map => map.WithName("Gender"))
            .Column(u => u.UserName, map => map.WithName("UserName"))
            .Column(u => u.UserPassword, map => map.WithName("UserPassword"))
            .Column(u => u.DateOfBorn, map => map.WithName("DateOfBorn"))
            .Column(u => u.OpeningDate, map => map.WithName("OpeningDate"))
            .Column(u => u.FederalRegistrationCode, map => map.WithName("FederalRegistrationCode"))
            .Column(u => u.StateRegistrationCode, map => map.WithName("StateRegistrationCode"))
            .Column(u => u.TownRegistrationCode, map => map.WithName("TownRegistrationCode"))
            .Column(u => u.Score, map => map.WithName("Score"))
            .Column(u => u.Type, map => map.WithName("Type"))
            .Column(u => u.Status, map => map.WithName("Status"))
            .Column(u => u.DateOfCreated, map => map.WithName("DateOfCreated"))
            .Column(u => u.Tags, map => map.WithName("Tags"))
            .Column(u => u.Contacts, map => map.AsFrozen());

实体列族

public class Users
{
    public Guid UsersId { get; set; }
    public string Name { get; set; }
    public string ImgProfileUrl { get; set; }
    public string UserName { get; set; }
    public string UserPassword { get; set; }
    public int? Gender { get; set; }
    public DateTime? DateOfBorn { get; set; }
    public DateTime? OpeningDate { get; set; }
    public int Status { get; set; }
    public string FederalRegistrationCode { get; set; }
    public string StateRegistrationCode { get; set; }
    public string TownRegistrationCode { get; set; }
    public int Type { get; set; }
    public int Score { get; set; }
    public DateTime DateOfCreated { get; set; }
    public IEnumerable<string> Tags { get; set; }
    public IEnumerable<contactsudt> Contacts { get; set; }
}

实体UDT

public class contactsudt
{
    public string Phone { get; set; }
    public string Celular { get; set; }
    public string Address { get; set; }
    public long Number { get; set; }
    public string District { get; set; }
    public string Postalcode { get; set; }
    public string Name { get; set; }
    public string State { get; set; }
    public string Country { get; set; }
}

配置实例

new Configuration<contactsudt, Users>();
new Table<Users>(UtilsDb.Session).CreateIfNotExists();

1 个答案:

答案 0 :(得分:2)

在尝试使用会话之前,每当您启动/创建会话时,请确保您使用会话对象registering your UDT。例如,要使用自动映射:

session.UserDefinedTypes.Define(
  UdtMap.For<contactsudt>()
        .Automap()
);

另外,请确保使用全局MappingConfiguration register your maps(在您给出的示例中的Maps.cs中),以便LINQ知道它:

MappingConfiguration.Global.Define<Maps>();

听起来你可能错过了用户定义的类型地图。