Working with SQL views in Entity Framework Core

后端 未结 6 2244
再見小時候
再見小時候 2020-11-30 03:07

For example, I have such model:

public class Blog
{
    public int BlogId { get; set; }
    public string Url { get; set; }

    public BlogImage BlogImage {         


        
6条回答
  •  一生所求
    2020-11-30 03:40

    Views are not currently supported by Entity Framework Core. See https://github.com/aspnet/EntityFramework/issues/827.

    That said, you can trick EF into using a view by mapping your entity to the view as if it were a table. This approach comes with limitations. e.g. you can't use migrations, you need to manually specific a key for EF to use, and some queries may not work correctly. To get around this last part, you can write SQL queries by hand

    context.Images.FromSql("SELECT * FROM dbo.ImageView")
    

提交回复
热议问题