We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,697 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Connection to local databse generate from entity data model

Hi I am the new in C# and I do some semestral project, I have done generating the entity data model, and I want to connect to the database from class by dbcontext using the ConnectionString. I have problem to bind a connection to these database. Can someone help me?

There are my classes:
1.) this classes throw me warning that is obsolete

public static class ConnectionSettings
    {
        public static String ConnectionString = ConfigurationSettings.AppSettings[@"data source=(localdb)\v11.0;initial catalog=SusibarDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""];

    }

2.)this is the the second: EntityContainer is the name in configuration of xml

ublic class ItemDbContext : DbContext
    {
         public ItemDbContext()
             : base("EntityContainer")
         { }

         public DbSet<Item> Items { get; set; }
    }

3.)this is the class to adding data into database

public class RequestModel
    {

        private EntityDbContext.ItemDbContext dbContext = new EntityDbContext.ItemDbContext();

        public int GetUnifishedRequestsCount() { return 5; }

        public void TestInsert() 
        {
            Item i = new Item();
            i.Id = 1;
            i.Name = "Test";
            i.Created = DateTime.Now;
            i.Deleted = false;

            dbContext.Items.Add(i);

            dbContext.SaveChanges();
        }
    }

4.)the main

class Program
    {
        static void Main(string[] args)
        {
            model.RequestModel model = new model.RequestModel();

            model.TestInsert();

            Console.WriteLine("...");
            Console.ReadLine();

        }
    }
2
Contributors
2
Replies
10 Hours
Discussion Span
5 Months Ago
Last Updated
3
Views
kubiak
Newbie Poster
18 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

no SqlConnection? using System.Data.SqlClient;

exception
Newbie Poster
20 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

OK i will use SqlConnection it was my first choice but i use that.

kubiak
Newbie Poster
18 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0593 seconds using 2.65MB