调用Linq.First()时,IDataRecord阅读器关闭

时间:2018-07-13 10:50:45

标签: c# sql linq datareader

对于像这样的一段正常工作的代码-

foreach (var dataRecord in dataRecords)
{
    return dataRecord.GetDateTime("MaxLogDate");
}

我尝试将其替换为

return dataRecords.First().GetDateTime("MaxLogDate");

但是我得到了-

System.InvalidOperationException: 'Invalid attempt to call MetaData when the reader is closed.'

您能指导我为何以及何时关闭此阅读器吗?

1 个答案:

答案 0 :(得分:0)

这是使用方法:

train_dataset = read_image_dataset_tfrecordfile(my_filenames)
train_dataset = train_dataset.repeat() # if you want to loop indefinitely
train_iterator = train_dataset.make_one_shot_iterator()

x, y = train_iterator.get_next()
# x, y will represent your data batches, fed with the next ones every time 
# they are called.
# So you just use them directly instead of placeholders:
prediction = cnn(x) 
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(
    logits=prediction, labels=y))
optimizer = tf.train.AdadeltaOptimizer().minimize(cost)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    for epoch in xrange(num_epochs):
        epoch_loss = 0
        for _ in xrange(int(1020/batch_size)):
            _, c = sess.run([optimizer, cost])
            # ...