使用LINQ从文件夹中获取文件 [英] Get file from file folder with LINQ

查看:82
本文介绍了使用LINQ从文件夹中获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中创建一个列,调用文件位置的存储字符串路径.

此列是FileUrl.

我知道我可以在LINQ中执行此操作以获取文件列表

I create a column in my database call the store string path of file locations.

This column is FileUrl.

I know I can do this in LINQ to get a list of files

from f in Directory.GetFiles((@"c:\temp"))
select f;


获取列表

如何用((FileUrl))替换((@@ c:\ temp))

学习很棒.


to get the list

How can replace the ((@"c:\temp")) with ((FileUrl))

Learning is awesome.

from p in Patients
from f in Directory.GetFiles((p.FilesUrl))
select f


我收到此错误方法" System.String [] GetFiles(System.String)"不支持SQL转换."


我的查询


我了解,但我无法做到.这是我的形式mvc的示例.

我有一个带有数据链接的表格网格,用于选择带有数据的行new @ Html.ActionLink("Details","Details",new {id = item.PatientsId})


I get this error "Method ''System.String[] GetFiles(System.String)'' has no supported translation to SQL."


my query


I understand, yet I am not able to do. Here is example of my form mvc.

I have a table grid with data link to select row with data new @Html.ActionLink("Details", "Details", new { id = item.PatientsId })

var pat = (from u in _db.aspnet_Users
                                 where u.UserName == User.Identity.Name
                                 join d in _db.Doctors on u.UserId equals d.UserId
                                 join p in _db.Patients on d.DoctorsId equals p.DoctorsId
                                 select
                                      new PatientsModel
                                           {
                                                PatientsId = p.PatientsId,
                                                ClientID = p.ClientID,
                                                DOB = p.DOB,
                                                Gender = p.Gender,
                                                Handedness = p.Handedness,
                                                RecordingDate = p.RecordingDate,
                                                TimeRecording = p.TimeRecording
                                           })  }).SingleOrDefault(i => i.PatientsId == id));


我需要添加FileUrl = p.FileUrl ,这是文件位置的字符串值.

当用户选择详细视图时

我有


I need to add FileUrl = p.FileUrl which is where the string value for the file location.

When a user select detail view

I have



    @foreach(模型中的变量名){
  • @name
  • }


    @foreach (var name in Model) {
  • @name
  • }

推荐答案


原因是作为IQueriable的LINQ查询将被编译为SQL查询.由于SQL中没有名为GetFiles的方法,因此您会收到该异常.如果在Linq查询中使用您的方法很重要,则必须使用Linq To Object而不是Linq to Sql.


希望对您有所帮助,
干杯
Hi,
The reason is that the LINQ query which is an IQueriable will be compiled to a SQL query. As there is no method in SQL named GetFiles you receive that exception. If it is important to have your method in the Linq Query then you must use Linq To Object rather than Linq to Sql.


I hope it will help,
Cheers


这篇关于使用LINQ从文件夹中获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆