c# - Silverlight Concurrent Data Sources for a Grid's Control -


i have following data model:

camp -> campevent <- event.

camp has campid , name associated it. event has eventid, name, start/end (dates). campevent has (campid,eventid)pk, campid fk, eventid fk.

the tables used create domain model , domain service consumed client side on silverlight.

i able display event's table in silverlight using grid.

the grid has 2 template columns - 1 display checkbox, , display name of event.

so problem somehow need check checkboxes when control goes in edit mode.

i've noticed grid doesn't have ondatabound event, or doesn't have way of setting state of each checkbox checked other through binding.

well, apparently in silverlight don't have luxury of messing around contents of gridviewrow. can, however, achieve changing underlying data source.

in above scenario have control used creating instance of camp , associating 1 or many events. in sense control can either create or update "camp" object , relationships events. control state controlled enumeration public enum mode { create, update }; , depending on value property has, control either one, or both of following binding binding operations:

  1. get event data , display in grid composed of rows having checkbox & label.
  2. check boxes denoting events in specific camp participates.

this nice , dandy in theory in principle realized silverlight needs discrete data source bind to. created collection of campevent custom object in every element has boolean prperty ischecked, along event name , event id. campevent object not domain entity object , used binding.

so achieve goal, these steps took.

  1. declare observablecollection t used binding. in case underlying data source t our event, , linq entity query used grab id , name of event , transforms campevent object ischecked property set false default.

  2. if control in create mode done. checkboxes in grid's template column two-way bound ischecked property of underlying data source. step 1 enough create default ui check boxes unchecked. otherwise go 3

  3. well, number 2 wrong, therefore control in "update" mode. if selectedcamp property of control set (and property of type camp). @ point create linq entitities query ask domain service include events associated specified camp.

  4. once response query arrives, iterate through every event object associated camp. every event received, check see if exists in our observablecollection data source. if does, set ischecked property true item. once data bind grid, events associated specific camp "checked".

  5. mission accomplished.

few words on database structure, domain models generated entity framework, , wcf ria.

well, turns out ef maybe 80% there out of box. tool not intelligent enough know many-to-many relationship is. in case camp , events have following structure:

camp -> participates in many -> events (many) events -> have many -> camps (as participants) 

so make happen need "joiner" table between camps , events. properly, joiner table should in theory have @ least 2 columns:

campid -> foreign key eventid -> foreign key

now create primary key table, should have:

campid + eventid -> composite primary key.

making our table have 2 fields. super important because relationship creates navigation property possible in ef.

when domain model generated, ef not create joiner table in model. enable navigation property between camp , event , vise versa there couple of things have happen on underlying domain service meta data object.

**1. locate camp metadata info. decorate ienumerble<event>events property with:

[include] [association("campevent", "campid", "eventid", isforeignkey=true)] 

and explain mean: include says whenever query domain model, please include every event specified camp(s). association says there association table between camp , event navigation property work. in lookup table camp has campid identifier , event has eventid. use find events specified camp(s)**.

2. same whatever other navigational properties have.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -