0

我目前正在尝试从包含大约 3-4 百万行的紧凑型 ce 数据库中读取一个大表。我目前的数据库大小为 832MB。用记录填充列表正在抛出OutOfMemoryException

样机代码:

    using (var con = new DomainContext())
    {
        foreach (var item in con.logRecords)
        {
            if (item.Info != null && item.Info != "")
                item.Timestamp = DateTime.ParseExact(item.Info, "MM.dd.yyyy HH:mm:ss.fff", culture).Ticks;
        }
        con.SaveChanges();

    }

新的方法,仍然没有得到它的工作......

        Task.Factory.StartNew(() =>
        {
            using (var con = new DomainContext())
            {
                for (int i = 0; i < 300; i++)
                {
                    try
                    {
                        var temp = con.logRecords.Where(p => p.Id <= i * 10000 + 10000 && p.Id >= i * 10000);

                        foreach (var item in temp)
                        {

                            if (item.Info != null && item.Info != "")
                                item.Timestamp = DateTime.ParseExact(item.Info, "MM.dd.yyyy HH:mm:ss.fff", culture).Ticks;
                        }

                        con.SaveChanges();

                    }
                    catch { }
                    GC.Collect();
                    Console.WriteLine(i.ToString());


                }
            }
        });
4

1 回答 1

0

我使用原生 SQL,将时间戳解析为 SQL 时间戳,然后使用 DATEDIFF( datepart 、 startdate 、 enddate )找到自 1970 年以来的秒数。自第 0 年以来添加的秒数。我失去了毫秒部分,但我想这是下一个最好的事情。

于 2016-08-01T10:34:05.033 回答