score:2
There is a subtle problem with views when used from Entity Framework.
If you have a table with EF, you need to have a primary key to uniquely identify each row. Typically, that's a single column, e.g. an ID
or something like that.
With a view, you don't have the concept of a "primary key" - the view just contains some columns from some tables.
So when EF maps a view, it cannot find a primary key - and therefore, it will use all non-nullable columns from the view as "substitute" primary key.
When EF now reads the data, it will get all the columns and create an in-memory object representing that row. If EF now later on reads another row from the database where those non-nullable columns that make up the substitute PK of your view are the same - then it'll think: "gee, I already have that row" and just add another copy of the same object into your result set.
So in this case, in the end you might end up having 18 identical rows in your EF result set - even though the SQL Server output properly shows different data. ......
UPDATE: as a possible solution, you could try to tap in the sys.columns
and sys.tables
catalog views which offer "better" columns - non-nullable ones, that aren't all the same for each column....
Try something like this:
CREATE VIEW [Core].[vwDataDictionary]
AS
SELECT
t.Name,
t.object_id,
c.Name,
c.column_id
-- possibly later more columns here....
FROM
sys.tables t
INNER JOIN
sys.columns c ON c.object_id = t.object_id
Source: stackoverflow.com
Related Query
- The result of a query returns the same value for COLUMN_NAME from an Entity Framework query, which doesn't make sense
- The given value of type String from the data source cannot be converted to type int of the specified target column
- C# - Remove rows with the same column value from a DataTable
- Entity Framework/LINQ Error: The column prefix 'Project1' does not match with a table name or alias name used in the query
- Using the Iqueryable list result from one query as the parameter for another?
- Send a new list to the result of the LINQ query from the list for C#
- Returning the result from a linq query but with one value modified
- Linq query to get the properties from object B which have the same name and type of object A
- Can I Use The Same Linq Code to Query for Different Conditions?
- LINQ returns wrong value for one specific column in SQL View query
- How can I get data from the Entity Framework if I only know the table name and the column name from which to get the data?
- How to write LINQ query for fetching the specific records and generating new result at the same time?
- C# Linq XML Query where multiple elements of same name from a parent node based on a child node value
- Entity Framework query the same table for the sequence of steps in WHERE
- Can I assign the result of a Linq query to the source variable of the same query?
- Query to determine whether more than one element has the same value for a property?
- Using LINQ to get column value from column name when you have the row?
- How to execute a linq query for each item in a list , use it in the where clause and return a collection from the result of each query?
- Searching for a value in a DataTable column returns empty when the value exists
- LINQ Query Result - dynamically get field value from a field name variable
- Take value from part of a LINQ query and add it to the result
- Using LINQ, can I verify a property has the same value for all objects?
- Could not find an implementation of the query pattern for source type 'System.Data.Entity.DbSet'
- How do I query an integer column for "starts with" in Entity Framework?
- Linq: How to query items from a collection until the sum reaches a certain value
- Entity Framework: Get all rows from the table for the ids in list
- LINQ query returns error "The expected type was 'System.Int32' but the actual value was null."
- LINQ-to-Entities, Ambiguous Column Name with association between two views with the same column name
- When called from 'VisitLambda', rewriting a node of type 'System.Linq.Expressions.ParameterExpression' must return a non-null value of the same type
- The result type of the query is neither an EntityType nor a CollectionType with an entity element type
More Query from same tag
- Why doesn't a separately instantiated Func<T,bool> predicate not translate into SQL with Entity Framework?
- How to get value from Dictionary to new Object in LINQ query
- Iterating through a list of elements inside an element with a specific index
- average values for given resolution of minutes for datetime value pairs
- How to query list in memory instead of database call
- Query with many-to-many relationship by linQ and filter result/ Get dynamic data by LINQ
- Linq-to-Entities Join vs GroupJoin
- Return children using LINQ to XML
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- SQL query with group by and where filtering a received parameter
- Join large list of Integers into LINQ Query
- LINQ Query-Select records where all the children meet a condition
- Linq- preferable value in select
- Decimal Arithmetic Overflow
- dynamic Linq queries with Entity Framework
- Something wrong into Linq method
- Custom Func<> delegate inside Linq where clause
- Grouping List elements and map to new model using Linq
- How do I decipher the Select method docs on MSDN?
- Fastest way to filter a dictionary and "simplify" its values in C#
- Calculate average of an specific data that can be neutral
- How do I convert a database number to hex when the field might be null?
- Linq: Grouping a list, sorting it and getting top x values?
- Dynamic Order By Entity Framework
- Store linq query as a variable without select statement
- gridview databind with linq query errors
- LINQ, Lists and Add items question
- Map queries to multiples entities with Database First EF5 and view them in a DataGrid
- Return a group where one of it's items is equal to a value
- Beginner mistake in Linq Extension Methods with Entity Framework