public static IEnumerable<Music> getMusic( decimal id, IDataProvider db ) { return db.MusicData.Where( m => m.id == id ).ToList(); }
That generates a comple time error:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<My_MSI.Net.Models.Entities.Music>' to 'System.Collections.Generic.List<My_MSI.Net.Models.Entities.Music>'. An explicit conversion exists (are you missing a cast?) My-MSI.Net\Controllers\AdminBackOfficeController.cs 260 28
When I hit the breakpoint I set and expand the results, I'm still seeing two identical records when I'm 100% positive that there are 2 different records in the database ( because when I look in the databse (SQL Server Managment Studio) I see two different
records:
Screaming Skin | No Exit | Blondie
Maria | No Exit | Blondie
Both records when I expand the results are:
Maria | No Exit | Blondie
Maria | No Exit | Blondie
All fields (except for the binary field) are set as Primary Keys.
You don't show us all related code. E.G How do you implemetn IDataProvider?
How do you implement the DAL? Did you hit the database somewhere?
And seems like the code automaically added more items to the collection somewhere. That is why you got the same result more than 1 or 2 + because of the filter parameter is unique.
IDataProvider is simply an Interface class that specfies what methods the EFDbContext Class should implement.
The EFDbContext class contains a set of DbSet<className> types and one method that has to do with setting up the connection string. Nothing exotic here at all.
And I have NEVER used a Filter with any of my classes, Don't even understand how to create a FILTER on a class!
The primary key used for this site is decimal because we expect to have a very large number of members and decimal seemed like the best choice for a primary key.
The Music table is a bit different than the other tables, in that the id field is a members id number and while the number is unique it will not be unique within the Music table because a single member is not limited to uploading only one song at a time.
That is why the Primary key on the Music table is a multi-part key:
id
songName
album
artist
This covers all of the textual fields in the table, the only other field is called music and is of type varbinary(MAX).
We do not expect a member to upload more than one copy of any song, therefore this mult-part key does provide uniquness.
I have never applied a filter to any of my DB classes and even if I wanted to I wouldn't know how to do that.
I use the id value because I want ALL of the Music data for this particual member.
Okay, we have the IDataProvider, followed by the EFDbContext, following by Music and you can see that there are no filters applied.
using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Objects; using System.Data.SqlClient; using System.Data.Objects.DataClasses; using System.Linq; using System.Text; using My_MSI.Net.Models.Entities;
using System.Data.Entity.ModelConfiguration.Conventions; using System.Linq; using System.Web; using My_MSI.Net.Models.Entities; using My_MSI.Net.Models.Abstract;
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using My_MSI.Net.Models.Abstract; using My_MSI.Net.Models.Concrete;
publicdecimal
id { get;
set;
} [Required(
ErrorMessage = "Song
Name is a requried field." )]
publicstring
songName { get;
set;
} [Required(
ErrorMessage = "Album
is a required field." )]
publicstring
album { get;
set;
} [Required(
ErrorMessage = "Artist
is a required field." )] publicstring
artist { get;
set;
} publicbyte[]
music { get;
set;
} [NotMapped]
publicstring
Status { get;
set;
}
public Music() {
}
public Music(
decimal
Id, string
SongName, string
Album, string
Artist, byte[]
song, IDataProvider
Db ) {
id = Id;
songName = SongName;
album = Album;
artist = Artist;
music = song;
eric2820
Contributor
2777 Points
1161 Posts
EF returning two identical records when 2 different records are in the table.
Dec 07, 2012 12:21 AM|LINK
I have this method in my Music Entities class:
public static List<Music> getMusic( decimal id, IDataProvider db )
{
List<Music> data = db.MusicData.Where( m => m.id == id ).ToList<Music>();
return data;
}
There are only 2 records in the database both with the same id field.
But this code returns two copes of the first of the two records.
How can I get all records for this id number?
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 07, 2012 05:48 AM|LINK
public static IEnumerable<Music> getMusic( decimal id, IDataProvider db ) { return db.MusicData.Where( m => m.id == id ).ToList(); }Weera
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 07, 2012 09:11 AM|LINK
That generates a comple time error:
Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<My_MSI.Net.Models.Entities.Music>' to 'System.Collections.Generic.List<My_MSI.Net.Models.Entities.Music>'. An explicit conversion exists (are you missing a cast?) My-MSI.Net\Controllers\AdminBackOfficeController.cs 260 28
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 12:42 PM|LINK
Even if using:
var data = db.MusicData.Where( m => m.id == id )
When I hit the breakpoint I set and expand the results, I'm still seeing two identical records when I'm 100% positive that there are 2 different records in the database ( because when I look in the databse (SQL Server Managment Studio) I see two different records:
Screaming Skin | No Exit | Blondie
Maria | No Exit | Blondie
Both records when I expand the results are:
Maria | No Exit | Blondie
Maria | No Exit | Blondie
All fields (except for the binary field) are set as Primary Keys.
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 07, 2012 02:25 PM|LINK
You don't show us all related code. E.G How do you implemetn IDataProvider?
How do you implement the DAL? Did you hit the database somewhere?
And seems like the code automaically added more items to the collection somewhere. That is why you got the same result more than 1 or 2 + because of the filter parameter is unique.
Weera
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 07, 2012 02:45 PM|LINK
IDataProvider is simply an Interface class that specfies what methods the EFDbContext Class should implement.
The EFDbContext class contains a set of DbSet<className> types and one method that has to do with setting up the connection string. Nothing exotic here at all.
And I have NEVER used a Filter with any of my classes, Don't even understand how to create a FILTER on a class!
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 07, 2012 02:55 PM|LINK
public static Music getMusic( decimal id, IDataProvider db ) { return db.MusicData.Find(id);public static IEnumerable<Music> getMusic( decimal id, IDataProvider db ) { return db.MusicData.ToList(); }Weera
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 07, 2012 03:07 PM|LINK
The primary key used for this site is decimal because we expect to have a very large number of members and decimal seemed like the best choice for a primary key.
The Music table is a bit different than the other tables, in that the id field is a members id number and while the number is unique it will not be unique within the Music table because a single member is not limited to uploading only one song at a time.
That is why the Primary key on the Music table is a multi-part key:
id
songName
album
artist
This covers all of the textual fields in the table, the only other field is called music and is of type varbinary(MAX).
We do not expect a member to upload more than one copy of any song, therefore this mult-part key does provide uniquness.
I have never applied a filter to any of my DB classes and even if I wanted to I wouldn't know how to do that.
I use the id value because I want ALL of the Music data for this particual member.
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 07, 2012 03:20 PM|LINK
I understood but could you show us?
Your EFDbContext and your IDataProvider interface.
theres's something wrong.
Weera
eric2820
Contributor
2777 Points
1161 Posts
Re: EF returning two identical records when 2 different records are in the table.
Dec 07, 2012 04:11 PM|LINK
Okay, we have the IDataProvider, followed by the EFDbContext, following by Music and you can see that there are no filters applied.
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Objects;
using System.Data.SqlClient;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Text;
using My_MSI.Net.Models.Entities;
namespace My_MSI.Net.Models.Abstract
{
public interface IDataProvider
{
DbSet<Banned> Banned { get; set; }
DbSet<Identity> Identity { get; set; }
DbSet<Photos> Photos { get; set; }
DbSet<Details> Details { get; set; }
DbSet<BankData> BankData { get; set; }
DbSet<Matrix> MatrixData { get; set; }
DbSet<Contacts> ContactData { get; set; }
DbSet<Product> ProductData { get; set; }
DbSet<Applications> Applications { get; set; }
DbSet<Suggestions> Suggestions { get; set; }
DbSet<Testimonials> TestimonialData { get; set; }
DbSet<Payment> PaymentData { get; set; }
DbSet<Transactions> Transactions { get; set; }
DbSet<Downloads> Downloads { get; set; }
DbSet<Blogs> Blogs { get; set; }
DbSet<Logins> Logins { get; set; }
DbSet<Register> Registeration { get; set; }
DbSet<Removals> RemovalData { get; set; }
DbSet<Autoresponder> Autoresponder { get; set; }
DbSet<Music> MusicData { get; set; }
DbSet<Earnings> Earnings { get; set; }
DbSet<Withdrawls> Withdrawls { get; set; }
DbSet<SponsorshipView> SponsorshipData { get; set; }
DbSet<LogErrors> LogErrors { get; set; }
}
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;
using My_MSI.Net.Models.Entities;
using My_MSI.Net.Models.Abstract;
namespace My_MSI.Net.Models.Concrete
{
public class EFDbContext : DbContext, IDataProvider
{
public EFDbContext()
{}
public DbSet<Banned> Banned { get; set; }
public DbSet<Identity> Identity { get; set; }
public DbSet<Photos> Photos { get; set; }
public DbSet<Details> Details { get; set; }
public DbSet<BankData> BankData { get; set; }
public DbSet<Matrix> MatrixData { get; set; }
public DbSet<Contacts> ContactData { get; set; }
public DbSet<Product> ProductData { get; set; }
public DbSet<Transactions> Transactions { get; set; }
public DbSet<Applications> Applications { get; set; }
public DbSet<Suggestions> Suggestions { get; set; }
public DbSet<Payment> PaymentData { get; set; }
public DbSet<Testimonials> TestimonialData { get; set; }
public DbSet<Downloads> Downloads { get; set; }
public DbSet<Blogs> Blogs { get; set; }
public DbSet<Logins> Logins { get; set; }
public DbSet<Register> Registeration { get; set; }
public DbSet<Removals> RemovalData { get; set; }
public DbSet<Autoresponder> Autoresponder { get; set; }
public DbSet<Music> MusicData { get; set; }
public DbSet<Earnings> Earnings { get; set; }
public DbSet<Withdrawls> Withdrawls { get; set; }
public DbSet<SponsorshipView> SponsorshipData { get; set; }
public DbSet<LogErrors> LogErrors { get; set; }
protected override void OnModelCreating( DbModelBuilder modelBuilder )
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating( modelBuilder );
}
}
}
And my Music class is:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using My_MSI.Net.Models.Abstract;
using My_MSI.Net.Models.Concrete;
namespace My_MSI.Net.Models.Entities
{
public class Music
{
public static IDataProvider db { get; set; }
public decimal id { get; set; }
[Required( ErrorMessage = "Song Name is a requried field." )]
public string songName { get; set; }
[Required( ErrorMessage = "Album is a required field." )]
public string album { get; set; }
[Required( ErrorMessage = "Artist is a required field." )]
public string artist { get; set; }
public byte[] music { get; set; }
[NotMapped]
public string Status { get; set; }
public Music()
{
}
public Music( decimal Id, string SongName, string Album, string Artist, byte[] song, IDataProvider Db )
{
id = Id;
songName = SongName;
album = Album;
artist = Artist;
music = song;
My_MSI.Net.Models.Entities.Music.db = Db;
Db.MusicData.Add( this );
( ( EFDbContext)Db ).SaveChanges();
}
public static List<Music> getMusic( decimal id, IDataProvider db )
{
List<Music> data = db.MusicData.Where( m => m.id == id ).ToList<Music>();
return data;
}
}
}
Now you've seen everything in the stack.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.