Even after dropping the Music table, and receating it, and putting the 4 filed index in place before any data was added, I'm still getting duplicated records in the result set.
You did wrong with the architecture. You's better take a look at the IUnitOfWork and Repository.
If you still continuos with this pattern you will never know where is the bug lives. Bugs will follow up
public static List<Music> getMusic( decimal id, IDataProvider db ) { List<Music> data = db.MusicData.Where( m => m.id == id ).ToList<Music>(); return data; }
This is not the right thing to do with "List<Music>" It should be IEnumerable<T> or ICollection<T> then return to List();
Tolist mean forgoes the data after return. No overhead
List<T> might add the data to the collection of List<T> that is why you get more than 1 or 2.
If you try to create more instance of the music class you might get 3 item.
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 07, 2012 07:02 PM|LINK
Even after dropping the Music table, and receating it, and putting the 4 filed index in place before any data was added, I'm still getting duplicated records in the result set.
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 07, 2012 07:39 PM|LINK
I added a third song to the database and guess what?
Now I'm getting THREE copies of the FIRST record from the database.
It has correct record count but incorrect records.
What's up with that?
How can I fix this?
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 07, 2012 08:37 PM|LINK
When I take the generated SQL statment and plug it into SQL 2008 R2's SQL Managemnet Studio, I get both expected records back.
When I use this simplified SQL statemnet and plug it into SQL 2008 R2's SQL Management Studio, I get both expected records back:
SELECT * FROM [dbo].[Music] where id = 1
This is leading me to believe that this is a bug within EF.
Can anybody reproduce this bug to confirm?
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 08, 2012 02:03 AM|LINK
Hello,
Your problem is a little strange. Please change from decimal to int and have a try.
If still fails, please import the Stored Procdure of your SqlCommand inside the EntityFramework and continue your work.
thaicarrot
Contributor
5132 Points
1465 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 08, 2012 07:17 AM|LINK
You did wrong with the architecture. You's better take a look at the IUnitOfWork and Repository.
If you still continuos with this pattern you will never know where is the bug lives. Bugs will follow up
public static List<Music> getMusic( decimal id, IDataProvider db ) { List<Music> data = db.MusicData.Where( m => m.id == id ).ToList<Music>(); return data; }Weera
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 08, 2012 10:22 AM|LINK
You mean something like this:
public static IEnumerable<Music> getMusic( decimal id, IDataProvider db )
{
Db = db;
IEnumerable<Music> data = db.MusicData.AsQueryable();
return data;
}
Well that has the same problem! The first record is repeated for the number of records in the table.
When I run the qurey on SQL Managment Studio, I get both reccords, thus I'm beginning to think that this is a bug within EF.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
thaicarrot
Contributor
5132 Points
1465 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 08, 2012 10:27 AM|LINK
I don't think that is the EF bug. Could you repro then put it into skydrive then we can try?
Weera
thaicarrot
Contributor
5132 Points
1465 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 08, 2012 11:36 AM|LINK
See I Repro your solution and it work find.
"PracticeSolution"
https://skydrive.live.com/?cid=B692C2CBAD70A05C&id=B692C2CBAD70A05C%21127
You should correct your architecture.
Weera
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 08, 2012 03:19 PM|LINK
I have a test project up running and published, now all I need is a way to get it to you. The zip file is 834 KB in size.
You can reach me at EircDill@outlook.com
And here is the create script for the Music table.
USE [My-MSI.Net]
GO
/****** Object: Table [dbo].[Music] Script Date: 12/08/2012 12:05:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Music](
[id] [decimal]
(18, 0) NOT NULL,
[songName] [nvarchar]
(50) NOT NULL,
[artist] [nvarchar]
(50) NOT NULL,
[album] [nvarchar]
(50) NOT NULL,
[time] [datetime2]
(7) NOT NULL,
[music] [varbinary]
(max) NOT NULL,
CONSTRAINT [PK_Music] PRIMARY KEY CLUSTERED
(
[songName] ASC,
[artist] ASC,
[album] ASC,
[time] ASC
)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
)
ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
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 08, 2012 03:39 PM|LINK
I've put the zip file up on my Sky Drive
And here is the link to the publisished.zip file:
https://skydrive.live.com/redir?resid=4E9EAC14BC59A352!106&authkey=!AMO-kDNeLh924E0
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.