我在 SQL Server 中有一个非常简单的视图,看起来像这样,其中Show是LEFT JOIN with Character表的结果:
+---------+----------+----------------------+
| Name | Surname | Show |
+---------+----------+----------------------+
| Enoch | Thompson | The Boardwalk Empire |
| Anthony | Soprano | The Sopranos |
| Walter | White | Breaking Bad |
+---------+----------+----------------------+
当我在我的应用程序中通过实体框架获取此表时context.CharacterView.ToList()
,结果如下所示:
+---------+----------+----------------------+
| Name | Surname | Show |
+---------+----------+----------------------+
| Enoch | Thompson | The Boardwalk Empire |
| Anthony | Soprano | The Boardwalk Empire |
| Walter | White | The Boardwalk Empire |
+---------+----------+----------------------+
但是,在 DB 中,CharacterView应该是这样。
创建视图查询
CREATE VIEW CharacterView AS
SELECT c.Name AS [Name],
c.Surname AS [Surname],
s.Name AS [Show]
FROM [dbo].[Characters] AS c LEFT OUTER JOIN
[dbo].[Shows] AS scen ON c.ShowId = s.Id