0

the following query

SELECT 
    t.NAME AS TableName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255 
GROUP BY 
    t.Name, p.Rows
ORDER BY 
    t.Name

returns a table that i want to display on the UI from entity framework. As you can see the table cannot be created because it's dynamic.

Can this be done using Entity Framework?

4

1 回答 1

0

使用 Context.Database.SqlQuery(yoursql) 并使用泛型重载并提供自定义类型。EF 将使用选定的列值填充模型,因此为模型属性提供与列相同的名称(例如 TableName、RowCounts)

于 2016-05-10T22:39:59.183 回答