Last active
January 3, 2016 04:29
-
-
Save robertmclaws/8409707 to your computer and use it in GitHub Desktop.
Computed Columns in Azure Mobile Services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE [yourmobileservicesschema].[Pictures] ( | |
[id] BIGINT IDENTITY (1, 1) NOT NULL, | |
[average_rating] AS ([yourmobileservicesschema].[GetAvgRatingForPicture]([id])), | |
PRIMARY KEY CLUSTERED ([id] ASC) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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