I have a Premiums table that I attempting to query using the following LINQ-to-SQL:
var premiums = sourcePolicyContext.Premiums.Where(prm => prm.Policy_Number == "07748106");
This runs the following SQL against the database:
exec sp_executesql N'SELECT [t0].[Policy Number] AS [Policy_Number], ' +
'[t0].[PremiiumType] AS [Premiium_Type], [t0].[Number], ' +
'[t0].[Effective Date] AS [Effective_Date], ' +
'[t0].[Entry Date] AS [Entry_Date], ' +
'[t0].[Collision Premium] AS [Collision_Premium], ' +
'[t0].[Non Collision Premium] AS [Non_Collision_Premium], ' +
'[t0].[Tow Premium] AS [Tow_Premium], ' +
'[t0].[Other Coverage1 Premium] AS [Other_Coverage1_Premium] ' +
'FROM [dbo].[Premium Table] AS [t0]' +
'WHERE [t0].[Policy Number] = @p0',
N'@p0 nvarchar(4000)',
@p0=N'07748106'
This query returns two rows when run directly, as expected. It also results in two LINQ to SQL entities, however the data in the two entities is just duplicates of the first row in the SQL query results. Why might this be happening?
premiumslook like?select * from [dbo].[Premium Table] where [Policy Number] = '07748106'returns two rows. The two rows returned, by both that query and the stored procedure, are distinct from one another. Different premium values, different premium types, etc... However it seems that LINQ-to-SQL recognizes there are two results, but fills both resulting entities with the data from only the first returned row.