Breeze.js, Can query a SQL view using Breeze?

谁说我不能喝 提交于 2019-12-13 07:39:56

问题


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,


回答1:


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




回答2:


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.




回答3:


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;
    }
}


来源:https://stackoverflow.com/questions/33555684/breeze-js-can-query-a-sql-view-using-breeze

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!