2

I had a look at Entity Framework, get object by ID.

I can't get that to work.

I specifically want the

WHERE [Extent1].[CatId] = 1

as I don't want to return everything that filter it as in

using (ApplicationContext db = new ApplicationContext())  
{
    IQueryable<Project> projects = db.Projects; // Get all
    var p =  (from i in db.Projects where i.Id == ProjectID select i);
    Console.WriteLine("Project #  {0} added and Named:{1} ", ProjectID, p.First().Name);
    Assert.IsNotNull(projects.First().Name);
}

So what I am looking for in SQL terms is

SELECT *   
FROM Projects 
WHERE id = 1

Hope that makes sense.

1
  • It's not really clear what the issue is. Are you just looking for db.Projects.Single(p => p.Id == ProjectID)? Commented Jun 26, 2015 at 14:03

1 Answer 1

0

You should be able to use LINQ fluent syntax:

var project = db.Projects.SingleOrDefault(i => i.Id == ProjectId);

Great LINQ reference and examples

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.