1,105,592 Community Members

Connection to local databse generate from entity data model

Member Avatar
kubiak
Newbie Poster
18 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

        }
    }
Member Avatar
exception
Newbie Poster
20 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

no SqlConnection? using System.Data.SqlClient;

Member Avatar
kubiak
Newbie Poster
18 posts since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: