score:8
though robert mckee's answer is plausible and raises an interesting point, it is not actually the primary issue that we had in mind when writing that section of the specification. the issue we actually had in mind was this:
class c
{
private list<int> mylist = new list<int>();
// only the code in c can add items to the list.
public ienumerable<int> items
{
get
{
return from item in mylist select item;
}
}
}
suppose you have a c
in hand. should you be able to write this code?
((list<int>)c.items).add(123);
the existence of a query on a list should not grant code which obtains the query the ability to change the list! it should grant that code the right to execute the query and no more.
now imagine that instead of a list<int>
, the query is actually wrapping a database call. if the caller can obtain the underlying database from the query then perhaps they can make queries or edits to that database that the author of the query did not intend them to make.
of course, linq is not designed to be a security system, and if it is your only line of defense against code that wants to attack your database, you're probably pretty vulnerable. but all security systems work better when their components use good "defense in depth". not ever leaking the collection that a query is querying is part of a defensive strategy.
for more on this feature, see my article on the subject:
score:1
possibly because it would break things like:
var data=(from c in customers select c);
if (something)
data=data.where(somethingelse);
it makes it more difficult to be abstract about the data if the source might be leaked down the chain rather than using the abstract model. you couldn't really use var data
if the query might change its type based on the parameters you use in the query itself.
Source: stackoverflow.com
Related Query
- Why not reveal the type and identity of the source to the client?
- The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- why is this linq query return a boolean and not the first result of the select?
- LinqToSQl and the Member access not legal on type exception
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Why does using anonymous type work and using an explicit type not in a GroupBy?
- The specified type member is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported
- Why one query works and not the other?
- The 'TypeIs' expression with an input of type 'Domain.Entities.Request' and a check of type 'Domain.Entities.Base' is not supported
- Refactor Linq code and "LINQ to Entities does not recognize the method"
- The property 'a' is not a navigation property of entity type 'b'. Why not?
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- Why are LINQ operators defined as extension methods on IEnumerable interface and are not part of the interface itself? C#
- Could not find an implementation of the query pattern for source type
- LINQ: returning 2 SELECTs in 1 IQueryable for pagination? Keeping in lines with the repository pattern and not changing the return type
- code first approach error: the specified type member 'yyyxx' is not supported in linq to entities
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet` 'Where' not found
- Why are stored procedures, functions, and views put into a .dbml file instead of the code file?
- Why does my LINQ to SQL query fail the first time ("Row Not Found or Changed") and succeed the second time?
- Getting "Could not find an implementation of the query pattern for source type 'ExcelQueryable<T>'. " Error
- Why did I get an exception "Cannot implicitly convert type 'bool' to 'long?'" when using the LINQ Sum method and how to fix it?
- Could not find an implementation of the query pattern for source type 'Join'
- Why do Users and Roles for ASP.NET identity not appear in Db Context
- Why does this generic method implementation NOT require the Type value to be passed?
- DataGridView shows type and not the value
- Why does Resharper suggest a code change and then complain about the change?
- The specified type member is not supported in LINQ to Entities. entity members, and entity navigation
- Why can the type of the parameter for InsertOnSubmit not be inferred from the usage?
- Why can I not use the same poco in code first in EF4.1 to project my data?
More Query from same tag
- How do I get all invoices for a customer using the Linq extensions in QuickBooks Online API v3?
- Trouble casting results of Select() to a List<T>
- Passing parameter to LINQ query
- How to query this in LINQ? C#
- Find most related post in many to many relationship
- Linq, how to delete items in the middle of a query return?
- XElement.Element failed to select the correct child node
- C# multiple OR conditions in LINQ query
- Change the sequens of columns in datatable with linq
- How to create a dynamic LINQ select projection function from a string[] of names?
- Entity Framework/LINQ: Selecting columns from multiple tables?
- How to add an in command to a where clause in LINQ?
- LINQ table enumeration with column enumeration
- Implementing a custom QueryProvider with in-memory query
- remove duplicate SelectListItem? distinct
- Type error trying to call Any() using Expression<Func<..>> from method
- How to Display result Values even null in c# Windows form with LINQ
- Finding similar properties within a list of objects
- LINQ Expression Problem
- Merge two IEnumerable with LINQ
- C# Linq rows to column
- Compound expression with variable comparator?
- Using LINQ/Lambda to validate data before continuing
- Implementation of [PARTITION BY] command by LINQ
- List<T> - distinction by T.field
- Linq to entities compare datetime with milliseconds precision
- Select Distinct rows when only one columns is different Linq
- Query not fetching all the records
- Conditional "orderby" sort order in LINQ
- Linq: read node innertext