Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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:
C#
dbentity db=new dbentity();
db.items.addobject(new item() {value=something});
db.savechanges();
Posted
Comments
[no name] 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 26-Dec-11 10:51am    
i use database first

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.
 
Share this answer
 
v2
Comments
Wendelius 26-Dec-11 14:14pm    
Good answer, my 5.
RaviRanjanKr 26-Dec-11 16:16pm    
Nice Answer, My 5+
Go through the link below it might solve all your doubts regarding C# and DataBase
Sqlserver and C#[^]
 
Share this answer
 
Comments
RaviRanjanKr 26-Dec-11 16:16pm    
5+
theanil 27-Dec-11 12:50pm    
 
Share this answer
 
Comments
RaviRanjanKr 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900