Damo
Damo

Reputation: 2070

Get the details of one IAsset from Azure

I'm getting to grips with Azure, specifically Media Services.

I want to collect the details of one media item I've uploaded and encoded in Media Services without downloading the entire AssetBaseCollection from Azure.

When I have 1000's of assets, I worry this is not the best way to do it but currently this is the only way I can access any asset details as below.

var assetList = _context.Assets.ToList();

If I try and query _context.Assets directly (single, firstordefault) I get an unsupported exception.

How can I collect only one asset (IAsset) from _context.Assets without pulling the entire collection and performing the query on the list instead?

Upvotes: 0

Views: 197

Answers (1)

astaykov
astaykov

Reputation: 30903

You can query the assets, but you have to first use the .Where(predicate bool), and then .FirstOrDefault.

Following code will get you only one asset without getting all of them into a list:

 public IAsset GetAssetById(string assetId)
        {
            var asset = _context.Assets.Where(x => x.Id.Equals(assetId)).FirstOrDefault();

            if (null == asset)
            {
                return null;
            }
            return asset;
        }

You can check rest of my code at the WaMediaWeb project, where I've wrapped in a Web Application almost everything you could do with Media Service.

Upvotes: 0

Related Questions