One of the labs is a LINQ to SharePoint lab. It has two parts
- a feature that creates an Employee list and a Project list
- a web part that queries the Employee list using LINQ.
By default, the list creation feature has “Web" scope, and the sample code relies on that scope—it casts “properties.Feature.Parent” to an SPWeb object in the FeatureActivated and FeatureDeactivating methods. The Web Part that depends on that feature has “Site” scope, and has to have “Site” scope.
Here’s the original method—note line #3:
Since I wanted to make the dependence explicit, I had to elevate the scope of the first feature to “Site” scope. Of course, that breaks the sample code. I revised the code to acquire the SPSite object and retrieved the web site from that object. Line 3 was replace by lines 3 through 5.
I made same change in the “FeatureActivated” method of the event listener. Now, I can deploy and retract in a single package.