Can someone help? I should receive 2 records. What is wrong with this code?
void Main()
{
using (var _context = new ApplicationDbContext())
{
var parks = _context.Parks;
parks.Dump(); }
}
public class ApplicationDbContext : DbContext
{
public DbSet Parks { get; set; }
}
public class Park
{
public int ParkID { get; set; }
public String MacAddress { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Zip { get; set; }
}
Comments
The logic to insert two records is missing in the code.
Those records reside in the Parks table in the DB that is part of the connection. Doesn't the Entity Framework connection connect me to the db? Or do I need to explicitly use the connection in my code?
If I run the following I get the results 2 records
var parks = Parks;
parks.Dump();
Have you selected a database in the "Connection" dropdown in the toolbar?
If so, you don't need anything in your query other than this:
(or even just "Parks" if the query language is set to "C# Expression").
As I said above, I have the EF Connection selected in the "Connection" Bar. I wanted to be able to run the code from my initial post so that I can figure out better linq queries for my EF API project. I'm just getting back into coding. I can write the query in sql, but when I put it into Linq I have issues. so I thought that initial code would be a great tool to use for my EF Project. So how do I get this to return the same as (Parks or Parks.Dump())
void Main()
{
using (var _context = new ApplicationDbContext())
{
var parks = _context.Parks;
parks.Dump();
}
}
I still don't really understand your question. Does the following help?
Welp, as I was typing my response I found the issue to my problem. I was making it way harder than it needed to be and by just trying to explain it I found my solution.
I do have another question but I'm sure it belongs in it's own thread...I write a query in MSSQL with a Between(startdate, enddate) and I get results. When I do the same in Linq but with the operators (>= or <=) I get no responses. Is there a way to add the between function to linq?