locked
Using Objects as datasource for a lightswitch app RRS feed

  • Question

  • Hello,

    I'm trying to develop a lightswitch app. It initially asks to connect to a datasource. But, in the project i'm working on, the lightswitch app is meant to be like a UI which easily provides grids and Edit/Update buttons and stuff. The data is read from a MySQL DB by another DLL.

    This dll also includes the MySQL.Data and sets up the connection, reads data and populates the Objects from the 'Bussiness_Objects' Layer and returns these Objects and the connection also.

    These objects contain the Data which has to be read and bound to Grids or lists and so on. The lightswitch app is to accept these objects, read the data contained inside them and bind this data to the UI controls. It should not directly connect to the DB.

    So, How do i set up such a scenario?

    I have tried including this DLL reference, but I see no way of making Lightswitch accept an Object as a DataSource...

    Tuesday, November 20, 2012 3:28 PM

Answers

  • Hi

    Basically you create a WCF Service that uses your dll to populate custom classes. You then attach to this WCF Service and Lightswitch will create entities for you to work with.

    From your description, you are only pulling the data for read-only view. So it shouldn't take that long to put something together.

    Take a look at this page http://lightswitchhelpwebsite.com/Blog/tabid/61/tagid/21/WCF-RIA-Service.aspx

    I would suggest subscribing to this site. Mr Washington has provided the solution to many a Lightswitch problem in the past.

    Regards

    Paul

    • Proposed as answer by Yann DuranModerator Wednesday, November 21, 2012 4:52 AM
    • Marked as answer by PRinCEktd1 Thursday, November 22, 2012 6:14 AM
    Tuesday, November 20, 2012 7:30 PM

All replies

  • Hi

    Basically you create a WCF Service that uses your dll to populate custom classes. You then attach to this WCF Service and Lightswitch will create entities for you to work with.

    From your description, you are only pulling the data for read-only view. So it shouldn't take that long to put something together.

    Take a look at this page http://lightswitchhelpwebsite.com/Blog/tabid/61/tagid/21/WCF-RIA-Service.aspx

    I would suggest subscribing to this site. Mr Washington has provided the solution to many a Lightswitch problem in the past.

    Regards

    Paul

    • Proposed as answer by Yann DuranModerator Wednesday, November 21, 2012 4:52 AM
    • Marked as answer by PRinCEktd1 Thursday, November 22, 2012 6:14 AM
    Tuesday, November 20, 2012 7:30 PM
  • Thanks Paul. I finally figured it out. I can make a WCF RIA service and use it. Great.

    I would like to know one more thing. This time, its about the ADO .NET Entity model.

    I have added it to my project and so i see the EDMX file. When i added it, there was this pop-up asking me to choose a datasource, and i had read that if pointed to an existing DB, the necessary Object classes/entities will be auto generated. But, i closed the dialogue thinking that i will set the datasource later. So how do i set the datasource and get it to autogenerate the entities now, after closing the dialogue?

    Is there a way to get ADO .net entity framework to autogenerate the entities using a pre/post build event, or from code? What if i embed a blank edmx into a class library and compile the library, then refer the library in my main project, can I get it to autogenerate the entities through code by writing something like:

    myLibrary.myEntityModel.functionToAutoGenerateEntities();

    somewhere in my main project start/entry point, then run the project so that this gets executed and creates the necessary files, after which i comment out the above line so that successive builds and runs do not generate/modify the entities again?

    Thursday, November 22, 2012 6:28 AM
  • Mine is a DB first approach.
    Say, i have a DB with a table named person.
    It has 2 columns:
    VARCHAR FirstName  & INT Age

    Now, in our program, we will create an object class
    Person.cs
    Class Person
    {
         string _firstName;
         int _age;

         public string FirstName
         {
            get{return _firstName;}
            set{_firstName = value}
         }

         public string Age
         {
            get{return _age;}
            set{_age = value}
          }
    }

    or something similar. When the DB is complex and has many tables and columns, it gets difficult to create these classes as there maybe lots of such object classes...

    I read somewhere that ADO .Net Entity Framework can automatically generate these object/class .cs files for you from your already existing DB. That kind of makes a developers work easier and his/her time more productive...

    How can this 'autogenerate object class' functionality of ADO .net be called from code behind? 
    Or can it be called only from the visual studio UI by right-click or when adding a new .edmx file?
    Friday, November 23, 2012 7:51 PM
  • Not a direct answer to your question, but you might also want to look at this thread describing how to combine multiple tables into one LS entity using a RIA domain service:

    http://social.msdn.microsoft.com/Forums/en-US/lightswitch/thread/058dfa79-0a8a-437c-90bb-6c67bfd4f9c5

    Regards


    Xander

    • Edited by novascape Saturday, November 24, 2012 12:56 AM
    Saturday, November 24, 2012 12:55 AM
  • Thanks Xander.

    I set up a WCF RIA service and it solved the first problem. Now, my lightswitch application points to this service as its datasource and things are fine.

    While i was doing this, another thought came up.  I have mentioned it as the second question above. Do you have any ideas on it?

    Saturday, November 24, 2012 9:32 AM