locked
How do I switch from external datasource to LS datasource and keep the same data entities? Need to edit design. RRS feed

  • Question

  • Hi all,

    I have a LightSwitch desk top application that I wrote back in 2011 right after LightSwitch was available using VS2010 and the necessary extensions.  I am now in the process of trying to upgrade that application using Visual Studio 2013 Version 12.0.30501.00 Update 2.  The first thing that I do to make my life easier so that I am not re-inventing the wheel is connect to a copy of the original database.  This makes things a bit easier in that I now don't have to re-create my data entities.  However it appears that even though this is a copy I cannot edit the design. Are there any flags or properties that I can flip to make the entities editable?

    I need to change the database design.


    Thanks, -ja

    Sunday, March 1, 2015 1:53 AM

Answers

  • Hi John,

    "Why is this such a difficult thing to do?" because it was not implemented in LightSwitch. The LightSwitch intrinsic database and the in-built designer are quite restrictive in how to design tables and relationships. An external database would have to match the LightSwitch rules, in particular for ID's, primary keys and foreign keys to stand a chance of reverse engineering.

    We have reverse engineered databases, more widely data definitions, into LightSwitch and achieved a degree of flexibility not possible through the LightSwitch entity designer. However, only a resulting schema and metadata result achievable through the designer will be officially supported.

    We are testing new functionality for our AIDE for LightSwitch tooling that supports some entity import/export and reverse engineering. This is not yet ready for release.

    If you are able to supply a database schema script and desired project name we will be able to feed that into our testing to produce a vanilla VS2013 LightSwitch project with desktop client and intrinisic database.

    Cheers

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.


    Monday, March 2, 2015 6:45 PM

All replies

  • Am I hearing you right you created the external datasource you are connecting to with Lightswitch back in 2011? If so why not just upgrade that project to Lightswitch version you have for 2013. Just remember to first uninstall the extentions you used then reinstall them after upgrading the project. see Link
    Sunday, March 1, 2015 2:17 AM
  • That would be great if I had the original source.  Unfortunately not so much.  Yes you are hearing me right.  I suppose it's an EF thing.  But on the face of it, it does seem a bit lame if you cannot do this sort of thing easily.  I don't know how many times in the real world (my day job), I have had to do just this sort of thing and then when we roll to a production environment... you get the picture.

    So, I guess the real question is:  If I have a database that I want to use a starting point for my application knowing full well I am going to have to change the design of the database down stream then if I am using EF I am SOL (Sorry, Out Of Luck)?  

    Seriously...  Please tell me there is an easy way to do this without having to re-input the design.


    Thanks, -ja

    Sunday, March 1, 2015 3:33 AM
  • What Exactly do you need to Edit? Do you have access to the Server the project is being served on? You could edit the source SQL code using SQL Server Management Studio. See the Quote from this Book Chapter 3 under the Heading "Moving Intrinsic Tables to an External Data Source" the second Paragraph says this is possible. I think LightSwitch 2011 used Version 2008 R2. Here is a Link to the help section for the tool that should provide a base of basic task you can do to Edit Database objects.

    Sunday, March 1, 2015 8:36 PM
  • Yes this is what I am having to do and I guess this is a solution, however it does not really answer my question.  Another solution which I am contemplating is just start over from scratch.  I already have the original design so I can use that as a reference.

    What I want to do is take a copy of the current database, e.g. detach and copy and re-attach, then make that internal to my LightSwitch project and be able to edit the design using the EF designer.  If the answer is, no you can't do that, which it seems to be then that would be an answer to my question.  If the answer is yes you can do that and here is how.  That is also an answer to my question.

    So is the answer, yes and here's how or no this is not possible?


    Thanks, -ja

    Monday, March 2, 2015 1:42 AM
  • So you need the Database structure only? if its not too complex of a solution I would just remake it.

    You need the Database stored information? I would export any of that you can using the export to excel button. Save the excel file as a text file btw you can import faster with a text file. Just make sure when you go the browse screen to select all files when looking for the exported info.

    Else if you want to detach a structure using say SQL Server Management Studio. I don't know its above my pay grade try asking that in the SQL forum

    • Edited by reigh7 Monday, March 2, 2015 4:02 AM
    Monday, March 2, 2015 3:58 AM
  • So since no one seems to be able to answer this question I will assume the answer is no you can't do this.  BTW, @reigh7 it's a piece of cake to detach a database and copy somewhere else using SQL Server Management Studio.  That's not a problem.

    Thanks, -ja


    Monday, March 2, 2015 7:28 AM
  • Hi,

    '... assume the answer is no ...', the answer is yes, we have done this, but you need certain skills and knowledge. There is no simple supported way.

    I am puzzled as to why you would want to bring an external database to internal. If you could explain what are the key reasons why, that would be helpful.

    Once external, you choose your tooling and do whatever extensions and changes that you want. Being internal is a bit more restrictive for database savvy developers.

    Cheers

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Monday, March 2, 2015 12:22 PM
  • Thanks Dave,  I think that if you read the entire thread you would know why.  So, I will repeat here. I have a LS application that I no longer have current source for and I want to get it to a state where it previously was.  I guess what I don't understand is Why is this such a difficult thing to do? If you could point me at an article of the internals of how this works I would greatly appreciate this.

    As to being a database savvy developer, I have been doing database development primarily on SQL Server since it was Sybase SQL Server and ran on OS2.  I have done the full gamut of development, Stored Procedures, CTE's, functions, used DDL with Power Shell to set up mirroring, etc.  So I know my way around SQL Server thank you very much.

    I just want to know why this is so difficult to do and if it can even be done....  Basically my original question.


    Thanks, -ja



    Monday, March 2, 2015 4:50 PM
  • Hi John,

    "Why is this such a difficult thing to do?" because it was not implemented in LightSwitch. The LightSwitch intrinsic database and the in-built designer are quite restrictive in how to design tables and relationships. An external database would have to match the LightSwitch rules, in particular for ID's, primary keys and foreign keys to stand a chance of reverse engineering.

    We have reverse engineered databases, more widely data definitions, into LightSwitch and achieved a degree of flexibility not possible through the LightSwitch entity designer. However, only a resulting schema and metadata result achievable through the designer will be officially supported.

    We are testing new functionality for our AIDE for LightSwitch tooling that supports some entity import/export and reverse engineering. This is not yet ready for release.

    If you are able to supply a database schema script and desired project name we will be able to feed that into our testing to produce a vanilla VS2013 LightSwitch project with desktop client and intrinisic database.

    Cheers

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.


    Monday, March 2, 2015 6:45 PM
  • Thanks Dave,

    I was just thinking, incorrectly, that since the database was originally created using LS then it would not be that big of a deal to reverse engineer. 

    At this point I have two VS solutions, one with external and one that has the intrinsic (I just re-created it).

    Please correct me if I am wrong.  There really is no need to have the intrinsic, the only reason for this is RAD in the beginning. Is that the only point of having it? 


    Thanks, -ja

    Monday, March 2, 2015 7:30 PM
  • I think you answered your question here. You can edit any part of the database with your SQL skills once you are familiar with Microsoft SQL Server. AND Lightswitch is a Rapid Application Developer tool specially tailored to people who want a simple way to visually create some basic databases. That's why I first asked what you wanted to change in your original Database to focus your question on the tool Yann Duram books says you can use to make further edits if you have access to the server. As Dave says you can reverse engineer it all I mean its just text files and folders but its a lot of work as well and you have to reprogram each part of the file structure including the .lsml's which hold the basic Entity framework it looks like an XML indented format like the following. I only mess with it when I know what to add were because it is a native code to lightswitch.

    <?xml version="1.0" encoding="utf-8"?>
    <ModelFragment xmlns="http://schemas.microsoft.com/LightSwitch/2010/xaml/model">
      <ServiceApplication
        Name="LightSwitchServiceApplication"
        Version="1.0.0.0">
        <ServiceApplication.Attributes>
          <ModuleNamespace
            Namespace="LightSwitchApplication" />
        </ServiceApplication.Attributes>
      </ServiceApplication>
      <DataService
        DataProvider="EntityFrameworkDataProvider"
        EntityContainer="LightSwitchCommonModule:ApplicationData"
        Name="ApplicationDataMapping">
        <EntitySetMapping
          EntitySet="LabPart" />
        <EntitySetMapping
          EntitySet="LabRBCDetail" />
        <EntitySetMapping
          EntitySet="LabOrderDetailsSet">
          <EntitySetMapping.Attributes>
            <SsdlForeignKeyProperty
              Name="LabOrderDetails_LabNames"
              Nullable="False"
              Type="int" />
            <SsdlForeignKeyProperty
              Name="LabOrderDetails_PPIsheet"
              Nullable="False"
              Type="int" />
            <SsdlForeignKeyProperty
              Name="LabOrderDetails_DiagnosisItem"
              Nullable="False"
    ...
    Tuesday, March 3, 2015 12:26 AM