开发者

Return record with maximum value stored as string using Linq to SQL

I am retrieving records that contain information about document versions. The document version number is stored as a string. The format is 8 numeric digits followed by a period followed by four numeric digits (regex ^/d{8}./d{4}$). Numbers stored as text开发者_如何学Python.

I have two functions in my data repository. One called GetAllVersions which returns all records in the version database, and another called GetLatestVersion which should return the record with the maximum version number.

My code looks like this:

public IQueryable<MyProject.Models.Version> GetAllVersions()
{
    var versions = from v in _datacontext.Versions
                   select v;
    return versions;
}
public MyProject.Models.Version GetLatestVersion()
{
    var dataset = GetAllVersions()
                 .Where(x => x.VersionNumber.ToString() == x.VersionNumber.ToString().Max());
    return dataset;
}

GetAllVersions works, but I cannot get the Linq to SQL syntax to return the record with the maximum version number. Is there a way to do this in Linq to SQL?

Thank you for your help.


GetAllVersions().OrderByDescending(x=>x.VersionNumber).First();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜