Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
C#
from f in Directory.GetFiles((@"c:\temp"))
select f;

to get the list

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

Learning is awesome.

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

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 })
C#
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));

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 (var name in Model) {
  • @name
  • }

Posted
Updated 5-Apr-12 8:01am
v4

1 solution

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
 
Share this answer
 
v3
Comments
postonoh 12-Apr-12 17:06pm    
public List<mycombinedquerymodel> Files(int? id)
{


var uploads = (from u in _db.Patients
where u.PatientsId == id
select u.FilesUrl).FirstOrDefault();


if (uploads != null)
{
var dir = new DirectoryInfo(uploads);

IEnumerable<fileinfo> filelist = dir.EnumerateFiles("*.*", SearchOption.AllDirectories);

var query = (from file in filelist
where file.Length > 0
let fileName = file.Name
select new MyCombinedQueryModel
{
FileName = file.Name
}).ToList();


return query;
}
return null;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900