Answer the question
In order to leave comments, you need to log in
Why is EntityFramework Core returning incorrect values from a view in the database?
Good afternoon.
Connoisseurs of .NET, tell me, please:
I have a view in the database, it returns such a data set
CAT 1 CAT 2 CAT 3 CAT 4 CAT 6 CAT 7 CAT 8 .....
I want to use it in ASP.NET through Code First . As usual, I create a context, model, connection, make a selection
List<v_FullTreeItem> m = db.v_FullTreeItems.OrderBy(x => x.Srt).ToList();
List<v_FullTreeItem> m = db.v_FullTreeItems.FromSql("SELECT * FROM v_FullTreeItems").ToList();
Answer the question
In order to leave comments, you need to log in
I solved the problem: I added the ROW_NUMBER() OVER(ORDER BY id) AS PKey field to the view, and indicated in the model that this is the primary key. Everything became normal. It didn't want to work correctly without a primary key.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question