This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
How is this done? The examples attempt to utilize the unitOfWork, but I need a complete example of this. The examples provided do not utilize the Lightspeed lsmodels. I tried to perform this action through adding a binding source to the LightSpeed entity, but the data in the datagrids never show (though the columns are correct). I also tried to bind in code through the UnitOfWork derived class to that entity, but also no good. And yes, I do have data in the table of interest. |
|
|
Could you clarify whether this is Windows Forms or Web Forms? Thanks! |
|
|
Sorry, Windows Forms. |
|
|
I've attached a (trivial) sample. Here are the steps I took: * Create WinForms project and add DataGridView to main form. * Create LightSpeed model. I used a simple model with two entity types, Comment and Member, with a one-to-many association from Member to Comment. * From the DataGridView tasks flyout, create a new data source. Choose Object, and choose Comment as the type of object. * Edit the column set if required (I had to do this because the grid wanted to interpret Comment.Message as an image rather than a string). * In the form constructor, create a LightSpeedContext and ensure the connection string etc. are all hooked up correctly. * In the form constructor, create a UnitOfWork by calling context.CreateUnitOfWork. (I saved the UnitOfWork as a member variable rather than disposing it immediately, because the DataGridView wanted to load the association from Comment to Member *after* the constructor had completed, and therefore threw errors if the UOW had been disposed. So I had to dispose the UOW in the form close event.) * Set the DataGridView.DataSource to a suitable LightSpeed query e.g. dataGridView1.DataSource = _unitOfWork.Find<Comment>() to load all comments. If you're using LINQ, setting the DataSource to the IQueryable doesn't seem to work (not sure why right now), but you can get around that by forcing the query, e.g. dataGridView1.DataSource = _unitOfWork.Comments.ToList(). Hope this helps -- please let us know if you still run into problems. |
|
|
Thanx! That worked great! I just needed a simple example to get me started :) |
|
|
Just one more answer, please. I have a table (named KEYTAB) with a primary key containing two columns, KEY_TYP and CODE. LightSpeed generates an ID class named "KeytabId. So far so good. But how do I display the values in the DataGridView?
|
|
|
You would need to create your own columns and map them to the Id.KEY_TYP and Id.CODE subproperties. Unfortunately I don't know whether the WinForms DataGridView supports multipart property paths like WPF does, so you may need to do some investigation. If that isn't possible, you can create wrapper properties on the KEYTAB class itself (via the partial class if you're using the designer), e.g. public int Code { and map your columns to these wrapper properties rather than directly to the ID. |
|
|
Hope this will help you......Datagridview Tutorial Vyar |
|