I've moved all the database access code to the Controller and guess what? It still doesn't work as well as SQL Server works.
All I want is all the records for a given id number. That shouldn't be so unusual.
In this case I only have 2 records in the table both with the same id number, but that will not always be the case so I need to pull the records by id number.
You see when a member uploads music to the server, it is his/her id number that goes into the id field. Thus the id field can not be unique. The id field does have an index though.
This query works in SQL Server Management Studio (2008 R2):
select *from [dbo].[Music]
where [id]
= 1
This SQL from the EF also works in SQL Server Managenent Studio (2008 R2):
{SELECT [Extent1].[id] AS [id], [Extent1].[songName] AS [songName], [Extent1].[album] AS [album], [Extent1].[artist] AS [artist], [Extent1].[time] AS [time], [Extent1].[music] AS [music] FROM [dbo].[Music] AS [Extent1]} where id = 1
The only place these quries fail to provide the desired result is when running under EF!
Using the code that you had pasted earlier, I tried to reproduce the issue in sample windows forms applicatin but for me it only returns one record. I used the exact same code that you pasted with only the Music Entity and also with the same lambda expression
i.e. db.MusicData.Where( m => m.id == id )
I would recommend you to open a support case with us to determine the cause. Visit this link to see the various support options that are available to better meet your needs: http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone."
Using the code that you had pasted earlier, I tried to reproduce the issue in sample
windows forms applicatin but for me it only returns one record. I used the exact same code that you pasted with only the Music Entity and also with the same lambda expression i.e. db.MusicData.Where(
m => m.id == id )
I would recommend you to open a support case with us to determine the cause. Visit this link to see the various support options that are available to better meet your needs: http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone."
Thanks,
Kunal
MSFT
I did report this BUG with Microsoft a while back in thier bug reporting site. I don't have the money to get paid support yet and won't until after I find a job again and fix the things that need fixing here.
That is why the Primary key on the Music table is a multi-part key:
id
songName
album
artist
You say that the above is your "multi-part key". If that's the case, instead of using
m => m.id == id to get a record you need use all of the fields that make up the key.
Reporting by definition is different. Otherwise we would just show it on the screen.
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 08, 2012 10:57 PM|LINK
I've imlemented the MusicCollection : ICollection<Music> backed by a private List<Music> and I set a breakpoint on the Add( Music m ) member:
What I saw was two idential records coming from the database!
Yet when I put the query string in SQL Management Studio, I get two different records.
What would you deduce from this result?
I'm getting closer to blaming the Entity Framework for this and I'll contract Microsoft about this issue on Monday.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 09, 2012 12:49 AM|LINK
OK. Now I've submitted your strange question to a senior development team to analyze this. If they have free time, I think they'll reply to you;)
Don't feel worried about that.
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 09, 2012 09:48 AM|LINK
Thank you.
I've moved all the database access code to the Controller and guess what? It still doesn't work as well as SQL Server works.
All I want is all the records for a given id number. That shouldn't be so unusual.
In this case I only have 2 records in the table both with the same id number, but that will not always be the case so I need to pull the records by id number.
You see when a member uploads music to the server, it is his/her id number that goes into the id field. Thus the id field can not be unique. The id field does have an index though.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 09, 2012 11:42 PM|LINK
This query works in SQL Server Management Studio (2008 R2):
select * from [dbo].[Music] where [id] = 1
This SQL from the EF also works in SQL Server Managenent Studio (2008 R2):
{SELECT [Extent1].[id] AS [id], [Extent1].[songName] AS [songName], [Extent1].[album] AS [album], [Extent1].[artist] AS [artist], [Extent1].[time] AS [time], [Extent1].[music] AS [music] FROM [dbo].[Music] AS [Extent1]} where id = 1
The only place these quries fail to provide the desired result is when running under EF!
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 13, 2012 09:29 PM|LINK
Any news from the seniour development team yet?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 18, 2012 03:36 PM|LINK
I was able to get it working by reveriting back to ADO.Net code. This just reinforces my idea that EF is BROKEN for my use case.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
kunalmundada...
Member
8 Points
4 Posts
Re: EF returning two identical records when 2 different records are in the table.
Jan 21, 2013 01:34 PM|LINK
Hi Eric,
Using the code that you had pasted earlier, I tried to reproduce the issue in sample windows forms applicatin but for me it only returns one record. I used the exact same code that you pasted with only the Music Entity and also with the same lambda expression i.e. db.MusicData.Where( m => m.id == id )
I would recommend you to open a support case with us to determine the cause. Visit this link to see the various support options that are available to better meet your needs: http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone."
Thanks,
Kunal
MSFT
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Jan 21, 2013 02:30 PM|LINK
I did report this BUG with Microsoft a while back in thier bug reporting site. I don't have the money to get paid support yet and won't until after I find a job again and fix the things that need fixing here.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
ryanbesko
Contributor
3607 Points
630 Posts
Re: EF returning two identical records when 2 different records are in the table.
Jan 21, 2013 04:19 PM|LINK
You say that the above is your "multi-part key". If that's the case, instead of using m => m.id == id to get a record you need use all of the fields that make up the key.
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Jan 21, 2013 07:11 PM|LINK
Because the id is not unquiet. As the member is allowed to upload mutuable songs and they are all stored with his/her id number.
That is how we have more than one record per id number.
Adding an uniquit key to the table doesn't really solve anything here because we still need to pull the records by id number.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.