0
votes

I am trying to learn about Breeze.js,

And it seems that Breeze requires that the back-end object has a PK defined. I my case I am trying to read data from a SQL View.

Can Breeze query a SQL view using Breeze? What is the workaround or a better alternative for this.

Thanks,

3

3 Answers

0
votes

Yes. My C# Model to SQL views looks exactly the same as those mappings to SQL tables.

0
votes

Yes you can.

Breeze required PK for two way binding, that is send back modified object to server for save changes.

In your case it's only one way you can use SQL view.

0
votes

The following is how i do it for a t-sql command. The same idea works for views (though we define those views in our model). Works great. Of course, no updating or adding, but that is to be expected.

internal class RvRDetail
{
    public string DistrictName { get; set; }
    public string EmployeeName { get; set; }
    public string SiteName { get; set; }
    public System.DateTime CalendarDate { get; set; }
    public string RevenueCategoryName { get; set; }
    public decimal TotalRepayment { get; set; }
    public decimal TotalRevenue { get; set; }
}

[BreezeController]
public class SeasonlessRvRController : BreezeAbstractApiController
{

    // GET: breeze/SeasonlessRvR/RvRData
    [HttpGet]
    public object RvRData(string districtList="", string showAllPeriods="0")
    {
        var returnData = _dbContextProvider.Context.Database
            .SqlQuery<RvRDetail>("SELECT * from dbo.udf_SeasonlessRvR(@DistrictList, @ShowAllPeriods)",
                            new SqlParameter("@DistrictList", districtList),
                            new SqlParameter("@ShowAllPeriods", showAllPeriods))
            .ToList();
        return returnData;
    }
}