I have no experience with .NET Entity Framework and I have to understand what exactly do this Entitity Framework query and translate in in classic SQL (for Microsoft SQL server)
So I have this query:
using (MyCorp.EarlyWarnings.Model.EarlyWarningsEntities context = new Model.EarlyWarningsEntities())
{
DBContext.SetTimeout(context);
float vulnerabilities_thisweek = (from x in context.VulnerabilityAlertDocuments
.Select(p => new { p.Id, p.Published, p.Title, p.Severity, p.LastUpdated })
.AsEnumerable()
.Select(p => new MyCorp.EarlyWarnings.Model.VulnerabilityAlertDocument()
{
Id = p.Id,
Published = p.Published,
Title = p.Title,
Severity = p.Severity,
LastUpdated = p.LastUpdated
})
.Where(p => p.LastUpdated.Date > DateTime.Now.AddDays(-7).Date)
select x).Count();
}
I know that the result of this query on my database is -1,00 (I know this information executing this query)
I also know that this query work on a single table (or at least I think it is so, correct if I am saying wrong thing) because I have from x in context.VulnerabilityAlertDocuments and in the EarlyWarningsEntities class I found this property that map the Data Base table named as VulnerabilityAlertDocument on the DbSet object named VulnerabilityAlertDocuments:
public DbSet<VulnerabilityAlertDocument> VulnerabilityAlertDocuments { get; set; }
So I think that my SQL query have to work only on the VulnerabilityAlertDocument database table.
I can't understand what exactly do when in the where condition use the => "operator", I have try to search on Google but I can't find nothing
I also have some difficulties to understand what exactly do the AsEnumerable() method called on the .Select() result.
Reading the documentation it seems to me that the first .Select() method return to me a set of rows and then it is called the AsEnumerable() method to have an iterator on this collection but I am not sure, do you confirm or is it wrong?
Then it execute a second select and I can't understand on what (it seems to me that the table is the same)
Someone can help me to understand what exactly do this query and how can I convert it in standard SQL?
Tnx