locked
Complex data type handling RRS feed

  • Question

  • Very new to LS but have been using SL + EF for a while.  I'm looking for some general advice.

    tl;dr version - How do I handle complex value types in LightSwitch?

    In previous (non-LS) applications I have developed a handy general purpose type (class).  I have a generic base class

    Range<T>  where T : IComparable<T>

    I use this type in many places within an application when another type needs something that is not a single value but which covers a range.  A Range instance may be closed (from 10 to 15 inclusive, or from 3/3/2009 up to but not including 1/1/2011) or may be open ended (greater than or equal to 10.0, or less than 100).  Each range has two values of type T (lower and upper) and fore booleans indicating if the lower and upper values are inclusive or exclusive and if the upper and lower values should be ignored).  The base class provides several checking methods (does one Range overlap another, does one range include another) and some convenience static factory methods.  In practice a subtype derives from the base generic class

    RangeDateTime : Range<DateTime>

    to record the period of time that a person in my contact system has a relationship with another party (Fred Bloggs was in Accounts department from 2/2/2010 to 5/5/2011)

    Obviously, I like my little utility class :-)

    Can I make use of this in a LightSwitch application?  I have an entity called Party (based on Martin owler's Analysis Patterns - Accountability) which may be a Person or a Company or a Department or ....  Then there are many relationships between Parties which are modeled using an entity called Accountability.  So, a particular person may be accountable to a particular Company from 2/2/2010 to 5/5/2011 and to a different Company from 6/5/2011 ongoing.  They may be a member of various Departments over various time ranges.  When a new Accountability between a Person and a Company is inserted then any existing Accountability which would overlap this new one is truncated so that it finishes on the day immediately preceding the start of this new one.

    In previous applications I have modeled this by having a property of Accountability of type RangeDateTime.  Entity Framework handled this nicely.

    Can I do the same sort of thing in LightSwitch?  Business Types don't seem to allow more than one underlying field (or have I missed something?).  Can something like this Complex type be handled with an Extension, if so what sort of extension would I use?  Is there another way?

    Any pointers, or advice (even if it is 'too hard, don't bother') is welcome.


    Paul Linton

    Wednesday, December 5, 2012 5:07 AM

Answers

  • Hi Paul,

    The short answer is that even though LightSwitch uses Entity Framework as its data persistence mechanism, & EF supports complex data types, LightSwitch itself doesn't support complex data types at all.

    About the closest you'll get (& it's not really a complex type) is explained in this article by Beth Massi.

    Using Different Edit Screens Based on Record Types (Table Inheritance)

    You might be able to make use of your utility class in validation code etc, but you can't use a complex data type for a property in a LightSwitch entity.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    • Marked as answer by PaulLinton Wednesday, December 5, 2012 9:31 PM
    Wednesday, December 5, 2012 5:23 AM
    Moderator