Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF Core在调用中获取字符串的一部分_C# - Fatal编程技术网

C# EF Core在调用中获取字符串的一部分

C# EF Core在调用中获取字符串的一部分,c#,C#,我已经建立了一个通用存储库,并从数据库中提取数据。我的部分数据包括文件上载信息,包括文件的存储位置: \\RemoteLocation\Desktop\TargetFolder\MyFile.csv 我想要的是删除MyFile.csv之前的所有部分,但我很难做到这一点。目前,我正在使用LINQ收集我需要的部分数据,如下所示: var fileData = _files.GetAll(); var latestFile = fileData.Where(x => x.FileLoadedT

我已经建立了一个通用存储库,并从数据库中提取数据。我的部分数据包括文件上载信息,包括文件的存储位置:

\\RemoteLocation\Desktop\TargetFolder\MyFile.csv

我想要的是删除
MyFile.csv
之前的所有部分,但我很难做到这一点。目前,我正在使用
LINQ
收集我需要的部分数据,如下所示:

var fileData = _files.GetAll(); 
var latestFile = fileData.Where(x => x.FileLoadedTime != null && x.LoadStatusId == 4 && x.EngineId == 1).ToList().Last(); // most recent is at the bottom of the list

有人能告诉我如何切掉我不需要的部分数据吗

有几种方法可以从路径获取文件名,您可以在下面尝试

使用:


您正在寻找的方法是
Path.GetFileName(yourPath)

我假设您的文件类如下所示

public class File{
    public DateTime FileLoadedTime;
    public int LoadStatusId;
    public int EngineId;
    public string Path;
}

var fileData = _files.GetAll(); 
var latestFile = fileData.Where(x => x.FileLoadedTime != null && x.LoadStatusId == 4 
                 && x.EngineId == 1).ToList().Last(); // most recent is at the bottom of the list

var path = Path.GetFileName(latestFile.Path);

如果我理解正确,那么您想要文件名而不是整个路径?是吗?@Prasadelkikikar是的。这是正确的
    string result =  latestFile.Split('\\').Last();
    Console.WriteLine(result);
public class File{
    public DateTime FileLoadedTime;
    public int LoadStatusId;
    public int EngineId;
    public string Path;
}

var fileData = _files.GetAll(); 
var latestFile = fileData.Where(x => x.FileLoadedTime != null && x.LoadStatusId == 4 
                 && x.EngineId == 1).ToList().Last(); // most recent is at the bottom of the list

var path = Path.GetFileName(latestFile.Path);