如何使用EF代码优先POCO创建一个视图 [英] How to create a view using EF code-first POCO

查看:352
本文介绍了如何使用EF代码优先POCO创建一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很简单。我需要创建一个查看使用代码第一次。我什么都没有发现这个对谷歌也没有那么。有没有办法做到这一点?

That simple. I need to create a View using Code First. I found nothing about this on google nor SO. Is there a way to accomplish this?

我需要创建的视图,并使用LINQ查询,所以它不是用在数据库创建一个脚本来创建一个解决方案,例如:

I need that view to be created and queried using linq, so it's not a solution to create it using an script on Database creation, for example:

var results = from c in db.Customer
join v in db.MyView on c.Id equals v.Id
select c;

一个解决办法是可以接受的。我需要一种方法来查询对非恒定/非实体值的实体。

A work around is also acceptable. I need a way to query entities against non-constant/ non-entities values.

推荐答案

您不能创建EF代码优先的观点做法。如果你想创建视图,然后在种子 execute方法创建SQL脚本。但你仍然无法实体映射到这种观点,除了通过创建和相同的名称视图将滴速表黑客模式。

You cannot create views with EF Code First approach. If you want to create view then execute creation sql script in Seed method. But you'll still not be able to map entity to this view, except hacking model by creating and droping table with same name as your view will have.

一些有用的链接

这篇关于如何使用EF代码优先POCO创建一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆