gpt4 book ai didi

entity-framework - 以代码优先方法映射 SQL View

转载 作者:行者123 更新时间:2023-12-03 12:17:43 24 4
gpt4 key购买 nike

我有一个 SQL View :

WITH DirectReports (ID,ParentFolderID, ParentFolderName,FolderID,FolderName,OwnerOCID,OwnerArName,OwnerEnName,FolderType,LEVEL)
AS
(
SELECT e.Id AS ID,cast(cast(0 AS binary) AS uniqueidentifier) AS ParentFolderID, cast('MainFolder - ' + MainFolders.enName AS nvarchar(250)) AS ParentFolderName,
e.Id AS FolderID, e.Name AS FolderName, WorkSpaces.Owner_Id AS OwnerOCID, OrgCharts.arName AS OwnerArName, OrgCharts.enName AS OwnerEnName,
MainFolders.Type AS FolderType, 0 AS LEVEL
FROM WorkSpaceFolders AS e INNER JOIN
MainFolders ON MainFolders.RootFolder_Id = e.Id INNER JOIN
WorkSpaces ON WorkSpaces.Id = MainFolders.WorkSpace_Id INNER JOIN
OrgCharts ON OrgCharts.Id = WorkSpaces.Owner_Id
WHERE e.Root = 1 AND e.Parent_Id IS NULL
UNION ALL
SELECT e.Id AS ID,e.Parent_Id AS ParentFolderID, d .FolderName AS ParentFolderName, e.Id AS FolderID, e.Name AS ChildFolderName, d .OwnerOCID, d .OwnerArName,
d .OwnerEnName, d .FolderType, LEVEL + 1
FROM WorkSpaceFolders AS e INNER JOIN
DirectReports AS d ON e.Parent_Id = d .FolderID)
SELECT *
FROM DirectReports

我正在使用代码优先迁移到我的数据库 - 如何将 View 映射到以下实体?
public class UserFolders
{
public Guid ID { get; set; }
public Guid ParentFolderID { get; set; }
public string ParentFolderName { get; set; }
public Guid FolderID { get; set; }
public string FolderName { get; set; }
public Guid OwnerOCID { get; set; }
public string OwnerArName { get; set; }
public string OwnerEnName { get; set; }
public int FolderType { get; set; }
public int LEVEL { get; set; }
}

最佳答案

View 可以映射为表。它应该是这样的:

public class UserFoldersMap : EntityTypeConfiguration<UserFolders>
{
public UserFoldersMap()
{
this.ToTable("view_name");

this.HasKey(t => t.Id);
}
}

希望能帮到你...

关于entity-framework - 以代码优先方法映射 SQL View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16890505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com