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
|
Hi, I've a grid connected with lightspeed. With a button I open a detail form for the selected row. Now, how can I pass my UoW filtered to the datail form so I can do the databinding?
Is correct this using of lightspeed or is a better method for parameter passing? |
|
|
It depends on your UOW lifecycle. If you are keeping the UOW alive for the duration of the form, you probably have it as a member variable of the form or the controller/presenter class, so you can just access that member variable. If you are using short-lived units of work, the unit of work is disposed by this stage, so you will need to create a new unit of work instead. For filtering, use a LINQ where clause (if you're using a short-lived unit of work, don't forget LINQ queries are deferred so remember to enumerate or call ToList() on the query *before* allowing the UOW to go out of scope), or the IUnitOfWork.Find method. |
|
|
I created a new UOW and I've used the Find method: using (ModelUnitOfWork uow = Repository.Context.CreateUnitOfWork()) How can I pass my UoW in iAnagraficaSoggetto as parameter? And parameter UoW in Init, as it should be declared? |
|
|
You don't pass your UOW into iAnagraficaSoggetto as a parameter; instead you add the new entity to the unit of work: AnagraficaSoggetto iAnagraficaSoggetto = new AnagraficaSoggetto(); I'm not sure about passing a UOW parameter to Init(): this will depend on what Init() does. But in general it probably shouldn't be necessary. But I'm slightly confused about what you're trying to do here. You're doing a Find() but discarding the results, then creating a new entity. You said earlier that you were wanting to open a detail form for the selected item. In that case you should be locating the selected item and using that, which would look something like this: IList<Soggetti> soggetti = uow.Find<Soggetti>(...); You should use new() and Add() only if the user is creating (inserting) a *new* entity. |
|
|
Hello Ivan, sorry if you get confused, but I'm beginning with C # and LightSpeed .. If I use your code : IList<Soggetti> soggetti = uow.Find<Soggetti>(...); I've this error: "Cannot convert type 'Prove.Soggetti' to 'Prove.AnagraficaSoggetto'" I've created .Init for initialize form with defaults such as form permissions, form dimension, ecc... It's a simple project to familiarize with LightSpeed. Thanx for your patience. |
|
|
Ah, this is probably my lack of Italian making me misunderstand. I thought AnagraficaSoggetto was a kind of Soggetto; with my Latin head on, I now realise it must be for form for editing Soggetti -- is that right? So ignore my previous post. I was talking nonsense. What you want to do is something like this: using (var uow = /* create unit of work */) { using (AnagraficaSoggetto form = new AnagraficaSoggetto()) { And in your Form.Init method you copy values from the selectedItem into the UI e.g. private Soggetti _itemToEdit; And in your change, validate or close event handlers you copy the contents of the UI back e.g. private void OKButton_Click { Note that for a production application you would probably want to move this stuff out into a controller or presenter and use the MVC or MVP pattern, but I'm assuming you don't want to bother with that for a familiarisation exercise. Hope this helps and apologise again for the misunderstanding in my previous post. |
|
|
Hi Ivan, no problem for the misunderstanding, also my english is rusty, thanks for availability. Thanx again |
|
|
If it's coming from your application, it probably means either uow or gridView1 is null. Fire the app under the debugger, break on that line, and hover over the variables to find which is null. If it's coming from inside LightSpeed, could you post the stack trace please? Thanks. |
|
|
Hi Ivan, I understand where was the problem. I wrote : gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SOGGEIDINDCF").ToString(), but the real column name is "Soggeidindcf". I made a stupid mistake... Now everything works!
Thanx again for the precious help! Bye |
|