i have this query (linq to entity) :
var query = from p in dbContext.Students
where p.Type == "پیش ثبت نام" && p.Approved == false
select p;
and as you see, i want to select all students with above condition,then i want Convert Result to Array with this code :
string[] strNumbers = dbContext.Students.Where(p=>p.Type=="پیش ثبت نام" && p.Approved==false).ToArray();
but above code its’not working : “Cannot implicitly convert type ‘NoavaranModel.Student[]’ to ‘string[]'”
and when i use this code :
string[] strNumbers = dbContext.Students.Where(p=>p.Type=="پیش ثبت نام" && p.Approved==false).Cast<string>().ToArray();
i get this error : “Unable to cast the type ‘NoavaranModel.Student’ to type ‘System.String’. LINQ to Entities only supports casting Entity Data Model primitive types. “.
then i want to Pass strNumbers to below Methode :
Utility.SendMessageForStudents(strNumbers);
Thanks in your Advise.
You have to return the string instead of student object which where clause returns. You can select student number using select method. Suppose student has StudentNumber