I create a view as you can see :
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
In my application I want to call it as you can see :
public List<DAViewMTO> ViewMTOByDetail()
{
List<DAViewMTO> lst = new List<DAViewMTO>();
lst = _ctx.Database.SqlQuery<DAViewMTO>("SELECT * FROM [SPMS2].[dbo].ViewMTO").ToList();
return lst;
}
But this query never returns any result. I put a break point in this function and the break point never passes this line:
lst = _ctx.Database.SqlQuery<DAViewMTO>("SELECT * FROM [SPMS2].[dbo].ViewMTO").ToList();
I have another views with another functions that have this structure and don't have any problem.When i execute my query directly in the SQL it doesn't have any problems.
I call it in the UI:
private void frmViewMaterialTakeOf_Load(object sender, EventArgs e)
{
splashScreenManager1.ShowWaitForm();
gridControl.DataSource = new BindingList<DAViewMTO>(_materialRepository.ViewMTOByDetail()) { AllowNew = true };
splashScreenManager1.CloseWaitForm();
}
[SPMS2]in your query ? Shouldn't that be the role of the connection string ? Second, if the functionViewMTOByDetailnever gets called, then you need to show where you're calling it._ctx.ViewMTO.ToList();Just like you map any other physical table.