i'm trying to figure out how I can use Linq to filter out some of my appsettings from my web.config file.
i'm trying to do something like the following (which has wrong syntax) :-
var query = from q in System.Web.Configuration.WebConfigurationManager.AppSettings.Keys
where q.StartsWith("Foo")
select q);
what have I done wrong?
edit: added screenie (here's a link to it)
alt text http://img21.imageshack.us/img21/5516/errorji.png
Readable code: LINQ makes the code more readable so other developers can easily understand and maintain it. Standardized way of querying multiple data sources: The same LINQ syntax can be used to query multiple data sources. Compile time safety of queries: It provides type checking of objects at compile time.
NET Core LINQ stands for Language Integrated Query. Language Integrated Query is one structured query that is used to retrieve data from the database and other different sources and formats. LINQ tutorials will assist you to find out the LINQ language using topics that go from basic to advanced.
You can use LINQ through the LinqDataSource control, through the ObjectDataSource control, or by creating LINQ queries. When you use LINQ in a Web application, you might have to change the policy files for code-access security.
The <appSettings> element stores custom application configuration information, such as database connection strings, file paths, XML Web service URLs, or any other custom configuration information for an application.
Try this if you want the values:
var settings = System.Web.Configuration.WebConfigurationManager.AppSettings;
var query = from string q in settings.Keys
where q.StartsWith("Foo")
select settings[q];
Could be because KeysCollection only implements IEnumerable not IEnumerable<T
>. Try using the Cast method on the Keys property first, something like:
var query = from q in System.Web.Configuration.WebConfigurationManager.AppSettings.Keys.Cast<string>()
where q.StartsWith("Foo")
select q;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With