Reading from Custom tables with PetaPoco Query method doesn't work
Hello,
I am trying to read data from custom tables in Umrbaco DB with
public IEnumerable<T1> Query<T1, T2>(string sql, params object[] args); but I don't get any exception and results are null.
Here is my source code:
[TableName("FacultyId")]
[PrimaryKey("FacultyId", autoIncrement = true)]
public class Faculty
{
public int FacultyId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
[TableName("Students")]
[PrimaryKey("Id", autoIncrement = true)]
public class Student
{
public int Id { get; set; }
public int StudentUmbracoId { get; set; }
[Required]
public string Name { get; set; }
[EmailAddress]
[Required]
public string Email { get; set; }
[Required]
public int ClassNumber { get; set; }
[Column("FacultyId")]
public int FacultyId { get; set; }
}
And my method for calling the SQL query is:
public IEnumerable<Student> GetStudentsByFaculty()
{
IEnumerable<Student> result = database.Query<Student, Faculty>("SELECT Students.*, Faculty.* from Students LEFT JOIN Faculty on Students.FacultyId = Faculty.FacultyId");
return result;
}
The result is :
I will be thankful if somebody can explain me where I am wrong.
Hi Alex,
Yes, I have them and when run this SQL in server Explorer I receive result.
Also I received results in backend too with Fetch<>, please see below:
public IEnumerable<Student> GetStudentsByFaculty()
{
var result = database.Fetch<Student, Faculty>(@"Select Students.*, Faculty.* from Students LEFT OUTER JOIN Faculty on Students.FacultyId = Faculty.FacultyId");
return result;
}
I think in this case you should use Fetch - there's a slight difference in the use of Query in that the latter doesn't load all the data into memory. See Query vs Fetch here. Probably in your first example if you expanded the results view you would see the data - but as I say, it looks to me that Fetch is what you would want to use here anyway.
Reading from Custom tables with PetaPoco Query method doesn't work
Hello, I am trying to read data from custom tables in Umrbaco DB with
public IEnumerable<T1> Query<T1, T2>(string sql, params object[] args);
but I don't get any exception and results are null.Here is my source code:
And my method for calling the SQL query is:
The result is :
I will be thankful if somebody can explain me where I am wrong.
Thanks, Desi
Hi Desi,
Do you have these tables in your db ?
Hi Alex, Yes, I have them and when run this SQL in server Explorer I receive result. Also I received results in backend too with Fetch<>, please see below:
I think in this case you should use Fetch - there's a slight difference in the use of Query in that the latter doesn't load all the data into memory. See Query vs Fetch here. Probably in your first example if you expanded the results view you would see the data - but as I say, it looks to me that Fetch is what you would want to use here anyway.
Hope that helps
Andy
Hi Andy, Thanks for your answer and advice. I will look at the article for comparison between Fetch and Query.
Thanks, Desi
is working on a reply...