Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robertmclaws/8409707 to your computer and use it in GitHub Desktop.
Save robertmclaws/8409707 to your computer and use it in GitHub Desktop.
Computed Columns in Azure Mobile Services
CREATE FUNCTION [yourmobileservicesschema].[GetAvgRatingForPicture](@pictureId bigint)
RETURNS int
AS
BEGIN
DECLARE @r decimal(3,2)
select @r = AVG(rating) from PictureRatings where picture_id = @pictureId
RETURN @r
END
CREATE TABLE [yourmobileservicesschema].[Pictures] (
[id] BIGINT IDENTITY (1, 1) NOT NULL,
[average_rating] AS ([yourmobileservicesschema].[GetAvgRatingForPicture]([id])),
PRIMARY KEY CLUSTERED ([id] ASC)
);
function insert(item, user, request) {
delete item.average_rating;
request.execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment