none
Binding database object RRS feed

  • Question

  • hi
    i have a windows application.
    i have a user interface which present data from database, create data from user input that will be added to databse through the application etc'.
    i have 2 question:
    1) i know that in ADO.net i can use dataset and define to the dataset insert, update and delete statement. i can display values with the dataset on grid, i can allow user edit the values and they will be updated on database with no effort by my side. is there a way to do something like that with linq? i know that i can bind table to grid, for example, as the data source but i couldnt succedd binding 2 tables with relations (one has a foreign key from the other) on grid. is there a way to do this? how can i use tables with relation and display the relation?
    in addition i tried binding one table to grid, edit values and than use submit changes function but the data in database is not being updated. is there a way doing that? again, its simple in ado.net but i couldnt find it in linq so i do all of the work by myself
    2) i have a stored procedure which retrieve data from some tables. i display it on grid. user do actions on that and create an entity which i need to insert to database. what is the correct way to work in such case? i am creating my own object of type that is very much like the dbml table (or the database table) that i want to insert the data into. after ceating the object and populating it i transfer the object to the data context layer, create object of the database table type, populate it with the data from the object and insert to database - this is a lot of work. i work like that because it seems to me incorrect to work with tables type of the database in a higher level than the data context layer. is this conccept correct? what is the best way to work in the described example?
    Monday, November 9, 2009 1:42 PM

Answers

  • Hi Michal,

     

     

    For the first question, you can set the LINQ query to bindingsource and set the bindingsource to the datagridview. When you want to save the changes that users do in the datagridview, you can add a button click event and add code like this,

     

    Bindingsoruce.EndEdit();

    DataContext.SubmitChanges();

     

    To bind two related tables, you’ll have to deal with inserting, updating, deleting all by code. If you could be more specific about your problem, I’ll give the detail steps for that.

     

     

     

    For the second question, since the SP is imported as function in LINQ to SQL, you’ll have to deal with the inserting by coding and call the SP in that method. If in Entity Framework, you can insert like the normal way, for example,

    Context. Stu.add(XXX);

    It will call the SP automatically as long as you map the SP in the entity.

     

    There is a type of architecture to manipulate the “Model” in the middle layer, Three Layer Architecture,

    http://www.codeproject.com/KB/cs/Three_Layer_Architecture.aspx

    In this article, it is described as Value Object. If your own object of type is like this, it is fine. You can also refer to this pattern of architecture.

     

     

     

    Best Regards

    Yichun Feng


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Yichun_Feng Monday, November 16, 2009 4:21 AM
    Friday, November 13, 2009 7:17 AM