Search code examples
angularjsbreeze

breeze - help starting out


I am working on a c#/mvc/breeze/angular project in visual studio and I was asked to build entirely new functionality. Currently, we have a stored procedure set up and it's being used in an entirely different place to pull data and now we are migrating this "worksheet" that uses this stored procedure to this c#/mvc/breeze/angular project. The stored procedure returns a regular record set - select * from mytable... it does several complicated things (not just basic querying) to return the records though...

I see in the c#/mvc/breeze/angular project so far, they only use stored procedures two types of ways: 1 way is if the stored procedure is returning a single value and the other way is if it is returning multiple selects like this : select * from table1 select * from table2 select * from table3.

My question is: how should I go about starting my project (adding it to this one...) - can I use the existing stored procedure or is there some way to integrate it with breeze to illiminate the need for the stored procedure...

I see they have a table styled worksheet set up (with filters) on this c#/mvc/breeze/angular project and I can't follow it exactly but it does not seem to be hitting a stored proc. I'm new to the breeze angular stuff.


Solution

  • If I understand correctly, you want breeze to retrieve the data produced by a stored procedure. Does this answer help?

    In short, you can define the class of the object you will be pulling from your stored procedure:

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

    Then in the controller, just run your stored procedure just as you would without breeze:

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

    Breeze will return in through the entity manager when you query the endpoint

    Since breeze will only be returning plain Javascript Objects, you could also do this with a non-breeze api endpoint using $http.

    If you want all the bells and whistles (caching, automatic wiring-up to other entities), you will have to create a view and include it in your model like a table, with the appropriate foreign keys and navigation properties defined.

    Hope this helps.