My linq query won't insert my data. What am I doing wrong?

    class Query
    {
        musicEntities db = new musicEntities();

        public bool findArtist(string artist)
        {
            bool status = db.Artists.Any(w => w.Name.Contains(artist));
            return status;
        }
        public void insertArtist(string artist)
        {
            if (findArtist(artist) == false)
            {
                Artist art = new Artist
                {
                    Name = artist
                };
                db.Artists.AddObject(art);
                db.SaveChanges();
            }
        }

    }

Recommended Answers

All 4 Replies

Why do you think it isn't inserting? When you check the database after you've run your program it isn't there?

No it is not in the database.

You do realize that Visual Studio makes a copy of file based databases when you run in debug mode and any changes you make will not persist in the database. You can see the copy in the debug directory while you are running your program.

Thank you. I did no realized that. I was able to connect to that database and display the data. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.