简体   繁体   中英

EntityFramework Code First: Generate view

I am working on a C# project that includes a MySQL database and EntityFramework layer. I am working with Code First. (This is because i work with xamarin/mono. There is no visual designer).

I want to create some mysql views (for performance reasons). 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 ?

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");
    }   
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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