7

Assume I'm working with the graph database from this sample (SQL Server 2017):

https://learn.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-sample

I have the following SQL query:

-- Find Restaurants that John likes
SELECT Restaurant.name
FROM Person, likes, Restaurant
WHERE MATCH (Person-(likes)->Restaurant)
AND Person.name = 'John';

I created a Model in C# using EF 6.1.3 and it autogenerates all the classes and everything from the database (EF Designer from database). This all works fine. I can even query all the people by using a simple method like:

public ICollection<People> ListPeople() => Entities.Peoples.ToList();

Now, if we come back to the original query, where I would like to find restaurants that John likes... how will I do this in Entity Framework? do I need to use a LINQ query or can I just call the entities? (presumably I can't because there doesn't seem to be any physical relationship between the tables, only by finding them in the edges)

I was thinking of something like

 public ICollection<Restaurant> ListRestaurantsLikedByPerson(string personName)
        {
            var result = from restaurant in Entities.Restaurants, person in Entities.Peoples, likes in Entities.likess
                where match (person - likes -> restaurant)
                and person.name = personName;

            return result;
        }

But this syntax is incorrect... how can I do this query?

Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
gbdavid
  • 1,639
  • 18
  • 40

2 Answers2

6

Entity Framework doesn't support the SQL server specific graph extensions.

NetMage
  • 26,163
  • 3
  • 34
  • 55
5

David Glass has put up a pull request for EntityFramework Core to be able to support SQL Server Graph capabilities, you could try using his modified version of EFCore and see how that works for you. I am busy trying to use it for working with SQL Graph tables as well.

https://github.com/aspnet/EntityFrameworkCore/issues/8527 https://github.com/aspnet/EntityFrameworkCore/pull/13804

EDIT: This PR has since been closed due to major structural changes to the internals of the latest release of EF core, and is inactive at the time.