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

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

问题描述

那么简单我需要使用Code First创建一个视图。我没有发现这一点在谷歌和SO。有没有办法完成这个?

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 Code First创建视图做法。如果要创建视图,请执行 Seed 方法中的创建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天全站免登陆