I have a problem in understanding some basic concepts here i think …
I am working on creating a a project for managing a complex database, (i am using linq to entities for my database that is in ms-sql 2012 and WPF )
I have 2 main problems:
I want to create a generic view for editing (remove update and insert) a large amount of tables from the database, i have no problem creating the list of tables manually but after that how can i manage it in a generic way ?
linq to entities does not allow doing something like :
string tableName = listbox.selectedItem.value;
var a = from p in db.tables[tableName] select p;
and even if i make all this manually for each table how can i create a UI that edits the information ? i need to dynamically create a form/view/user_control for editing that will contain items such as textbox and datetimepickers for each column… but i cannot make a generic selection for a table …
The other problem i have is manipulating data,
lets say i have a TASK table in the database
var tsks = from p in TASKs select new {p.task_id, p.task_description, p.task_date}
and i want to load it all to a gridview but instead of the task_date column i need it to be manipulated from a function for example :
02/12/2012 will show "From Today"
30/11/2012 will show "From 2 days ago"
and i just dont know how to connect this kind of function to the data-binding
I’ve tried creating sql-functions
I’ve tried calling functions in the code and tried to create extension functions for the entity but always got stuck and failed.
Just to make things clear, i have some nice experience in .net tech but WPF and LINQ is new to me,
i could easily create all Above in asp.net or windows form application using direct contact to the SQL DB without linq
therefore i understand i have a problem with some basics understanding and would to get answers to my 2 questions and will be more than happy to get directions to relevant tutorials
I’ll try to answer the second question. I recommend you read a little about binding in WPF and the MVVM design pattern first, it will help you understand how to use WPF’s datagrid, it’s works different that in win forms.
And to answer the question, After you bind the date property to a column, you can easily create a value converter, see this example:
http://wpftutorial.net/ValueConverters.html.
In your case you’ll need a DateTime to string converver