实体框架“从字符串中选择日期时间”

时间:2016-07-18 11:12:39

标签: c# entity-framework datetime datetime-parsing

我需要从表格中选择日期间隔的记录。

但是选择的日期在此模式中保持为nvarchar

20160511_155015 (yyyymmdd_hhmmss)

我无法使用ToList()将其设为DateTime.ParseExact(entry.StartDate, "yyyyMMdd_HHmmss", CultureInfo.InvariantCulture)

该表保留了数百万条记录。 所以我需要做这样的事情:

var preQuery = context.Table
              .AsNoTracking()
              .Select(x => new
             {
                StartDate = ConvertFrom()),
                Mode = x.Mode,
                SessionStart = x.AStart,
                SessionEnd = x.AEnd,
                x.SensorNumber
            })
            .Where(x => x.StartDate != null 
                   && x.StartDate >= startDate
                   && x.StartDate <= endDate)
            .ToList();

是否可以将字符串表示转换为Datetime,然后继续使用Where子句?

2 个答案:

答案 0 :(得分:0)

您可以尝试: StartDate.StartsWith(“20160511”)左右.. 要么 Convert.ToInt32(StartDate.Substring(0,8))&gt; 20160511

顺便说一下,我想你可能想要运行一个脚本,只要它需要,并创建一个新的列,它将根据该列生成一个DateTime

答案 1 :(得分:0)

  

请尝试此var marquee = $('.marquee'); var go = true; marquee.hover( function() { go = false; }, function() { go = true; } ); marquee.each(function() { var mar = $(this), indent = mar.width(); mar.marquee = function() { if (go) { indent--; mar.css('text-indent', indent); if (indent < -1 * mar.children('.marquee p').width()) { indent = mar.width(); } }; } mar.data('interval', setInterval(mar.marquee, 1000 / 60)); });

IFRDocument document = engine.CreateFRDocument();
document.AddImageFile("c:/temp/ctrk.bmp", pim, null);
IDocumentProcessingParams idpp = engine.CreateDocumentProcessingParams();
idpp.getPageProcessingParams().getRecognizerParams().setDetectLanguage(true);
document.Process(idpp);
if(document.getBusinessCards().getCount() > 0)
{
    IBusinessCard card = document.getBusinessCards().getElement(0);
    card.ExportToVCard("c:/temp/abbyy.vcf");
}