Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi
can't understand how to manage database with etnity framework
i'll try to describe my problem step-by-step
1) create winforms application
2) add database(.mdf) to solution
3) when appears window "choosing database model", select dataset
4) then finish, as database is empty
5) go to server explorer, choose created database, create some tables
6) add to solution EDM ADO.NET
the problem is that new data don't appears in my database in server explorer. this means that while my winforms app is working, i can modify my db (change existing values, add new, ..). but if i close my app, there is no update in my database in server explorer. i DON'T forget to use function SaveChanges()
 

P.S. while my app is working, values are updating. think, that means that data updates in dataset, but not in database. if i am right, give a clue how to update database from dataset.
pps. visual studio 2010 ultimate. sorry for english(
 
code ex:
dbentity db=new dbentity();
db.items.addobject(new item() {value=something});
db.savechanges();
Posted 26-Dec-11 5:37am
Comments
AnnieMacD at 26-Dec-11 10:50am
   
It's not clear if you are using Database First, Code First or Model First. You need to use DataContext to access the data.
alex10311 at 26-Dec-11 10:51am
   
i use database first
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Assuming your EDM is dbentity:
using (var myContext = new dbentity())
{
    var person = new Person();
    // add some stuff here to populate
    myContext.Person.AddObject(person);
    myContext.SaveChanges();
}
If 'person' is an object in the entity model, that's all that's required to add a record to a table in the database. (Replace 'person' with your own object).
 
Good luck and supply your code if this doesn't work for you.
  Permalink  
v2
Comments
Mika Wendelius at 26-Dec-11 14:14pm
   
Good answer, my 5.
RaviRanjankr at 26-Dec-11 16:16pm
   
Nice Answer, My 5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Go through the link below it might solve all your doubts regarding C# and DataBase
Sqlserver and C#[^]
  Permalink  
Comments
RaviRanjankr at 26-Dec-11 16:16pm
   
5+
theanil at 27-Dec-11 12:50pm
   
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
RaviRanjankr at 26-Dec-11 16:16pm
   
5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 202
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 26 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100