Linq Exclude from separate list

 var urlList = new List<DisplayAssets>();

 
 var assetsToExclude = (from a in db.DisplayAssets
                join h in db.Hardware_Assets on a.id equals h.displayId
                where h.assetId == hardwareid
                select a.id);

var allAssets = db.DisplayAssets;

var urls = allAssets.Where(x => !assetsToExclude.Contains(x.id));

        urlList = urls.Select(a => new DisplayAssets()
        {
            locaterAddress  = a.locaterAddress,
            assetType = a.assetType,
            id = a.id
        })
        .ToList();

Comments

Popular posts from this blog

Sorting Ascending and Descending

Linq Query Syntax vs Method Syntax