Member Avatar for kubiak

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();

        }
    }

no SqlConnection? using System.Data.SqlClient;

Member Avatar for kubiak

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

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.