Method 'System.String[] GetFiles(System.String)' has no supported translation to SQL."
Not every statement can be converted into a standard LINQ successfully……So you can use AsEnumerable first to convert from a standard LINQ statement into LINQ-TO-OBJECT and do deal with the problem:
var result = from p in Patients
from f in Directory.GetFiles((p.FilesUrl)).AsEnumerable()
where p.XXX == f
select f;
When user click on the detail actionlink. It deplays properly. In my patients table I have a column title FileUrl which capture the dynamic path of the newly created directory. So if when a user creates a new submission form they enter a client ID if the
ID exist it attaches a random number at the end then saves the string path to FileUrl. So now I trying to do this, when a client go to look that client ID it display all submitted information but instead of showing the files it is showing the file path.
because I am having such a hard time with this do you think I should just save the files in the sql database.
create a table called Uploaded files with a FK to Patients table and have the files loop through and save them there.
Code to read the files instead of pull there locations.
Yes,I think you can do this。
However if you only want to fetch all the files whose names are something related to that……Maybe you can use
System.IO.Directory.GetFilesfunction do deal with your problem
postonoh
Member
498 Points
259 Posts
Get file from file folder with LINQ
Apr 05, 2012 03:07 PM|LINK
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;
to get the list
did this
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."
How can replace the ((@"c:\temp")) with ((FileUrl))
thaicarrot
Contributor
5130 Points
1464 Posts
Re: Get file from file folder with LINQ
Apr 05, 2012 05:22 PM|LINK
Not sure did you convert the URL to string?
Weera
postonoh
Member
498 Points
259 Posts
Re: Get file from file folder with LINQ
Apr 05, 2012 05:53 PM|LINK
tried it still error
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Get file from file folder with LINQ
Apr 07, 2012 02:00 AM|LINK
Not every statement can be converted into a standard LINQ successfully……So you can use AsEnumerable first to convert from a standard LINQ statement into LINQ-TO-OBJECT and do deal with the problem:
var result = from p in Patients from f in Directory.GetFiles((p.FilesUrl)).AsEnumerable() where p.XXX == f select f;postonoh
Member
498 Points
259 Posts
Re: Get file from file folder with LINQ
Apr 08, 2012 05:42 AM|LINK
this is my code how to I incorporate the code you gave me.
public ActionResult Details(int? id) { var patients = ((from p in _db.Patients from f in Directory.GetFiles((p.FilesUrl)).AsEnumerable() join a in _db.AssessmentInformations on p.PatientsId equals a.PatientsId join b in _db.BehaviorInformations on p.PatientsId equals b.PatientsId join c in _db.CurrentMoods on p.PatientsId equals c.PatientsId join d in _db.DietInformations on p.PatientsId equals d.PatientsId join mb in _db.MedicalBackgrounds on p.PatientsId equals mb.PatientsId join med in _db.MedicationInformations on p.PatientsId equals med.PatientsId join ps in _db.PsycologicalBackgrounds on p.PatientsId equals ps.PatientsId join nu in _db.NeurofeedbackInformations on p.PatientsId equals nu.PatientsId join o in _db.OtherDataInformations on p.PatientsId equals o.PatientsId join na in _db.NarrativeInformations on p.PatientsId equals na.PatientsId join s in _db.SupplementsInformations on p.PatientsId equals s.PatientsId select new MyCombinedQueryModel { PatientsId = p.PatientsId, ClientID = p.ClientID, DOB = p.DOB, Gender = p.Gender, Handedness = p.Handedness, RecordingDate = p.RecordingDate, TimeRecording = p.TimeRecording, EO = p.EO, EC = p.EC, Task = p.Task, Referred_for = p.Referred_for, Evaluation_Number = p.Evaluation_Number, Years_of_Education = p.Years_of_Education.Value, Marital_Status = p.Marital_Status, Abnormality = p.Abnormality, Vision = p.Vision, Appearance = p.Appearance, Sleep_Disorder = p.Sleep_Disorder, Accident = p.Accident, Employed = p.Employed, Veteran = p.Veteran, Activities = p.Activities, Overweight = mb.Overweight, Hypertension = mb.Hypertension, Diabetes = mb.Diabetes, TBI = mb.TBI, Migraine = mb.Migraine, Thyroid = mb.Thyroid, Stroke = mb.Stroke, Tremor = mb.Tremor, Parkinson = mb.Parkinson, Kidney = mb.Kidney, Liver = mb.Liver, Lung = mb.Lung, Heart = mb.Heart, Paralysis = mb.Paralysis, Cerebral_Palsy = mb.Cerebral_Palsy, Weakness = mb.Weakness, ADD = ps.ADD, ADD_ADHD = ps.ADD_ADHD, ADHD = ps.ADHD, Anxiety = ps.Anxiety, ASD = ps.ASD, Austism = ps.Autism, Bipolar = ps.Bipolar, Dementia = ps.Dementia, Depression = ps.Depression, Eating_Disorder = ps.Eating_Disorder, Insomnia = ps.Insomnia, LD = ps.LD, OCD = ps.OCD, Psycological_Panic = ps.Psycological_Panic, PDD = ps.PDD, Schizophrenia = ps.Schizophrenia, Seizure = ps.Seizure, Psycological_Other = ps.Psycological_Other, Anxious = c.Anxious, Apprehensive = c.Apprehensive, Cheerful = c.Cheerful, Depressed = c.Depressed, Elevated = c.Elevated, Euphoric = c.Euphoric, Fearful = c.Fearful, Optimistic = c.Optimistic, Panic = c.Panic, Pessimistic = c.Pessimistic, Tearful = c.Tearful, Tense = c.Tense, Worried = c.Worried, Caffeine = d.Caffeine, Tobacco = d.Tobacco, Diet_Other = d.Diet_Other, Exercises = b.Exercises, Violent_Offense = b.Violent_Offense, Violent_Victim = b.Violent_Victim, Trauma = b.Trauma, Speech = b.Speech, Behavior_Other = b.Behavior_Other, Medication = med.Medication, MedDosage = med.MedDosage, Supplements = s.Supplements, SuppDosage = s.SuppDosage, Beck_Despression = a.Beck_Depression, Conners = a.Conners, DSM = a.DSM, IVA = a.IVA, MMSE = a.MMSE, TOVA = a.TOVA, WAIS = a.WAIS, WISC = a.WISC, Assessment_Other = a.Assesment_Other, Therapy_Used = nu.Therapy_Used, Angio = o.Angio, CT = o.CT, EEG = o.EEG, Lumbar = o.Lumbar, MRI = o.MRI, Neuro_Exam = o.Neuro_Exam, X_Ray = o.X_Ray, Other_Data_Other = o.Other_Data_Other, NarrativeSummary = na.NarrativeSummary }).SingleOrDefault(i => i.PatientsId == id)); return View(patients); }Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Get file from file folder with LINQ
Apr 08, 2012 06:18 AM|LINK
Hello:)
Doesn't your code work now?In fact just use AsEnumerable——the extended method,and in fact you've used……It should work……
postonoh
Member
498 Points
259 Posts
Re: Get file from file folder with LINQ
Apr 08, 2012 02:24 PM|LINK
The code works, yes.
When user click on the detail actionlink. It deplays properly. In my patients table I have a column title FileUrl which capture the dynamic path of the newly created directory. So if when a user creates a new submission form they enter a client ID if the ID exist it attaches a random number at the end then saves the string path to FileUrl. So now I trying to do this, when a client go to look that client ID it display all submitted information but instead of showing the files it is showing the file path.
example data is what is being display right now.
clientID = 231232
DOB 12/08/1970
FileUrl = "c:\directory\username\231232\"
I need this instead
clientID = 231232
DOB 12/08/1970
<table>
-table grid-
FileUrl = list the files in this directory.
</table>
so instead of the string path.
I need to display the files in the directory.
Thank you for spending time with on this.
postonoh
Member
498 Points
259 Posts
Re: Get file from file folder with LINQ
Apr 08, 2012 04:06 PM|LINK
because I am having such a hard time with this do you think I should just save the files in the sql database.
create a table called Uploaded files with a FK to Patients table and have the files loop through and save them there.
Code to read the files instead of pull there locations.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Get file from file folder with LINQ
Apr 09, 2012 01:07 AM|LINK
Yes,I think you can do this。
However if you only want to fetch all the files whose names are something related to that……Maybe you can use System.IO.Directory.GetFiles function do deal with your problem
postonoh
Member
498 Points
259 Posts
Re: Get file from file folder with LINQ
Apr 09, 2012 06:41 PM|LINK
I need a additional help.
I have create the following.
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form" }))
{
}
Using this allow me to access the orginal action request..
I created a table call FileUpload
FileId = PK
PatientsId FK
BinaryData varbinary(max)
Name varchar(255)
MimType varchar(255)
UploadDate (DateTime)
create the the following code
public int AddFile(byte[] byteArray, string filename, string mimType) { var linqByteArray = new Binary(byteArray); var file = new FileUpload { BinaryData = linqByteArray.ToArray(), MimeType = mimType, Name = filename, UploadDate = DateTime.Now }; _db.SaveChanges(); return file.PatientsId; }I am still having a problem
calling the <input type="file" ID="file" name="file" runat="server" multiple="multiple" />
C-sharp Linq mvc