C# C语言中带有嵌套对象的Cassnara大型集合插入#

C# C语言中带有嵌套对象的Cassnara大型集合插入#,c#,cassandra,bulkinsert,C#,Cassandra,Bulkinsert,在与卡桑德拉数据库长期斗争之后,我写下了这个问题。我想插入大量电影对象集合(~1000000): public class Movie { public Guid Id { get; set; } public string Title { get; set; } public string Description { get; set; } public int Year { get; set; }

在与卡桑德拉数据库长期斗争之后,我写下了这个问题。我想插入大量电影对象集合(~1000000):

    public class Movie
    {
        public Guid Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public int Year { get; set; }
        public string Genres { get; set; }
        public int Rating { get; set; }
        public string OriginalLanguage { get; set; }
        public string ProductionCountry { get; set; }
        public int VotingsNumber { get; set; }
        public Director Director { get; set; }
    }
使用嵌套字段控制器:

    public class Director
    {
        public Guid Id { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public int Age { get; set; }
    }
我使用的是DataStax C#Driver,我用了不同的方式绑定,但仍然没有。当前我的代码如下所示:

    private void CreateSchema()
    {
        Session.Execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication " +
                        "= {'class':'SimpleStrategy', 'replication_factor':3};");
        Session.Execute("CREATE TYPE IF NOT EXISTS test.director (" +
                        "firstname text," +
                        "lastname text," +
                        "age int," +
                        ");");
        Session.Execute("CREATE TABLE IF NOT EXISTS test.Movies (" +
                        "id uuid," +
                        "title text," +
                        "description text," +
                        "year int," +
                        "genres text," +
                        "rating int," +
                        "originallanguage text," +
                        "productioncountry text," +
                        "votingsnumber int," +
                        "director frozen<director>," +
                        "PRIMARY KEY (id)" +
                        ");");
    }

    public string TimeOfCollectionInsert(int collectionEntriesNumber)
    {
        var watch = new Stopwatch();

        try
        {
            IList<Movie> moviesList = Movie.CreateMoviesCollectionForCassandra(collectionEntriesNumber);
            var preparedStatements = new List<PreparedStatement>();
            var statementBinding = new List<BoundStatement>();

            for (int i = 0; i < collectionEntriesNumber; i++)
            {
                preparedStatements.Add(Session.Prepare("INSERT INTO test.Movies (id, title, description, year, genres, rating, originallanguage, productioncountry, votingsnumber, actors) VALUES (?,?,?,?,?,?,?,?,?,{ 'director': { firstname: 'DirectorName', lastname: 'DirectorLastname', age: 50 }});"));
            }
            for (int i = 0; i < collectionEntriesNumber; i++)
            {
                statementBinding.Add(preparedStatements[i].Bind(moviesList[i].Id, moviesList[i].Title, moviesList[i].Description, moviesList[i].Year, moviesList[i].Genres, moviesList[i].Rating, moviesList[i].OriginalLanguage, moviesList[i].ProductionCountry, moviesList[i].VotingsNumber));
            }

            watch.Start();
            for (int i = 0; i < collectionEntriesNumber; i++)
            {
                Session.Execute(statementBinding[i]);
            }
            watch.Stop();

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        return watch.ElapsedMilliseconds.ToString();

    }
private void CreateSchema()
{
Session.Execute(“如果不存在,则创建密钥空间,使用复制进行测试”+
“={'class':'SimpleStrategy','replication_factor':3};”;
执行(“如果不存在,则创建类型test.director(”+
名文本+
“姓氏文本,”+
“年龄整数,”+
");");
Session.Execute(“如果不存在,则创建表test.Movies(”+
“id uuid,”+
标题文本+
说明文本+
“整年,”+
“类型文本,”+
“评级为int,”+
“原始语言文本,”+
productioncountry文本+
“votingsnumber int,”+
“董事冻结,”+
“主键(id)”+
");");
}
CollectionInsert的公共字符串时间(int collectionEntriesNumber)
{
var watch=新秒表();
尝试
{
IList moviesList=Movie.CreateMoviesCollectionForCassandra(collectionEntriesNumber);
var preparedStatements=新列表();
var statementBinding=新列表();
对于(int i=0;i
这两种方法都成功运行,但我希望动态创建控制器。 我将非常感谢您的帮助。

顺便问一下,这是测量卡桑德拉批量插入性能的好方法吗

谢谢,
P

您必须将您的Cassandra UDT(用户定义类型)

控制器
映射到您的
控制器
C#类。
有关更多信息,请阅读文档: