我创建了一个视图,你可以看到:
CREATE VIEW [dbo].[ViewMTO]
AS
SELECT
dbo.Lines.Unit, dbo.Lines.LineNumber, dbo.Lines.DocumentNumber,
dbo.BaseMaterials.Name AS MaterialName,
dbo.MaterialDescriptions.Name AS MaterialDescription,
dbo.MaterialDescriptions.Description,
dbo.MaterialScopes.ScopeName, dbo.MaterialScopeObjectNames.ObjectName,
dbo.MaterialDescriptions.Size1, dbo.MaterialDescriptions.Size2,
dbo.MaterialDescriptions.ItemCode, dbo.Materials.Quantity,
dbo.Materials.Discipline
FROM
dbo.Materials
INNER JOIN
dbo.Lines ON dbo.Materials.LineId = dbo.Lines.Id
INNER JOIN
dbo.BaseMaterials ON dbo.Lines.BaseMaterialId = dbo.BaseMaterials.Id
INNER JOIN
dbo.MaterialDescriptions ON dbo.Materials.MaterialDescriptionId = dbo.MaterialDescriptions.Id
INNER JOIN
dbo.MaterialScopes ON dbo.MaterialDescriptions.MaterialScopeId = dbo.MaterialScopes.Id
INNER JOIN
dbo.MaterialScopeObjectNames ON dbo.MaterialDescriptions.MaterialScopeObjectId = dbo.MaterialScopeObjectNames.Id
在我的应用程序中,我想调用它,因为你可以看到:
public List<DAViewMTO> ViewMTOByDetail()
{
List<DAViewMTO> lst = new List<DAViewMTO>();
lst = _ctx.Database.SqlQuery<DAViewMTO>("SELECT * FROM [SPMS2].[dbo].ViewMTO").ToList();
return lst;
}
但是这个查询永远不会返回任何结果。我在这个函数中设置了一个断点,断点从不通过这一行:
lst = _ctx.Database.SqlQuery<DAViewMTO>("SELECT * FROM [SPMS2].[dbo].ViewMTO").ToList();
我有另一个具有此结构的其他函数的视图,并且没有任何问题。当我直接在SQL中执行查询时,它没有任何问题。
我在UI中调用它:
private void frmViewMaterialTakeOf_Load(object sender, EventArgs e)
{
splashScreenManager1.ShowWaitForm();
gridControl.DataSource = new BindingList<DAViewMTO>(_materialRepository.ViewMTOByDetail()) { AllowNew = true };
splashScreenManager1.CloseWaitForm();
}