简体   繁体   English

EntityFramework代码优先:生成视图

[英]EntityFramework Code First: Generate view

I am working on a C# project that includes a MySQL database and EntityFramework layer. 我正在研究一个包含MySQL数据库和EntityFramework层的C#项目。 I am working with Code First. 我正在使用Code First。 (This is because i work with xamarin/mono. There is no visual designer). (这是因为我使用xamarin / mono。没有视觉设计师)。

I want to create some mysql views (for performance reasons). 我想创建一些mysql视图(出于性能原因)。 How should i do to create the view ? 我应该如何创建视图? I've created all views in mysql but is there a way to "describe" this view in a C# class, in order to make it work with Entity Framework ? 我已经在mysql中创建了所有视图,但是是否有一种方法可以在C#类中“描述”此视图,以使其与Entity Framework一起使用?

Working with views is the same as working with tables. 使用视图与使用表相同。 You just map them using code first attributes or fluent configuration. 您只需使用代码优先属性或流畅的配置来映射它们。 The only thing that you can't do is update entries, you can just query the data. 唯一不能做的就是更新条目,您只需查询数据即可。

public class MyViewConfiguration : EntityTypeConfiguration<MyView>      
{
    public MyViewConfiguration()
    {
        this.HasKey(t => t.Id);
        this.ToTable("myView");
    }   
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM