You are here:   Forum
Register   |  Login

 

Forum Notice

This Forum is ARCHIVE only
For LightSwitch questions,
please use the official forums at:

http://social.msdn.microsoft.com/forums/en-US/lightswitch/threads


Forums

Creating A WCF RIA Service Using Entity Framework
Last Post 26 Jul 2013 06:05 AM by admin. 48 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Page 1 of 3123 > >>
Author Messages
Michael WashingtonUser is Offline
Send Private Message
Posts:1110
Avatar

--
11 Jun 2011 06:34 PM
    Here are directions to create a WCF RIA Service that uses a Entity Framework database. This demonstrates a web deployed application, and the method to set the connection string for the Entity Framework class in the web.config.

    NOTE: Also see

    WCF RIA Service: Combining Two Tables

    (for an article that shows how to connect to the existing database that the LightSwitch application is using)















































    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    fishyUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:86
    Avatar

    --
    12 Jun 2011 01:25 PM
    Thanks for doing this.

    Fishy
    CiroUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:1
    Avatar

    --
    15 Jun 2011 01:26 PM
    Hi Michel!

    I follow your tips and it worked nice. I have some questions, as I'm absolutely begginer about RIA, please, be patient with me:

    1- The copy and paste tasks (App.config and Web.Config) are only necessary after publishing the solution? I didn't do this part and the code worked nice in Visual Studio environment.

    2- Is it possible to use the procedure (your tip) to access LightSwitch intrinsic tables?

    Thanks to share this tip with us.

    Best regards,

    Ciro.
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    15 Jun 2011 03:01 PM

    1- The copy and paste tasks (App.config and Web.Config) are only necessary after publishing the solution? I didn't do this part and the code worked nice in Visual Studio environment.

    2- Is it possible to use the procedure (your tip) to access LightSwitch intrinsic tables? 
      


    Thank you for the feedback.

    1) Yes but the key will not be there and the EF Class in the WCF RIA Service will use whatever values were used to create the EF class. So when the key was not found it used that connection you used when you orginally imported the tables into the EF class.

    2) Yes
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Thom CUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:1
    Avatar

    --
    26 Jun 2011 04:12 PM
    Michael,

    I appreciate your work with LightSwitch for the dev community. You continue to go above and beyond the call.

    This blog was particularly well timed as I've been struggling with creating a LS-friendly WCF RIA service for more than a week without success. There are several other blogs and tutorials about this process, all of them wrong.

    I'm having similar problems with your technique. IOW... it doesn't work.

    When I try to add WCF RIA Service as a LightSwitch data source, LightSwitch just stops at the "Choose a WCF RIA Service" dialog, presumably because it doesn't recognize a valid WCF RIA Service as being available. It's not locking up (I appreciate your warning about the time LightSwitch can take finding services), it just doesn't "see" the WCF RIA Service. I suspect this is because the Domain Service resides in a simple C# class library project.

    Some questions:
    1) The project you're using to host the Domain Service is a simple C# class library. How is LightSwitch to understand this is a WCF RIA Service?

    2) When I create the simple C# class library project, there is no App.config file created by the template. Are you adding one after the project is created?

    3) In your LinqToEntitiesDomainService, your default query is returning this.ObjectContext.vw_UserRoles. When I try this, LightSwitch will not accept the data source because the object being exposed by the WCF RIA Service's default query has no key property defined. Typically, you get around this by creating a class in the DomainService with all the return object's properties and mark the appropriate property with the [Key] attribute. Then you use a Linq query to cast the collection of entities into the new return object (with a defined key property).

    Again, I thank you for your community-oriented efforts and I hope you have some insights into the problems I'm having.

    Regards,
    Thom C.
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    26 Jun 2011 06:56 PM
    @ThomC - on the Downloads page ( http://lightswitchhelpwebsite.com/D...loads.aspx ) please download:
    ■Creating a Simple LightSwitch RIA Service (using POCO)
    ■Saving Files To File System With LightSwitch
    They both contain WCF RIA services so you can see them work.

    1) You create a reference to the project using a wizard and it inspects the class and find the service
    2) The App.config is created when you use the Wizard to connect to create the Entity Framework (EF) class
    3) Yes
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    27 Jun 2011 10:16 AM
    Probably a stupid question but I would like to add multiple tables. I still only need one Domain Service, correct? Also, do I only mark one of the
    IQueryables<>
    with the
    IsDefault=true
    or do I need to do it for each table?

    Thanks,
    Sa souvraya niende misain ye!
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    27 Jun 2011 10:25 AM
    Posted By Refracted Paladin on 27 Jun 2011 10:16 AM
    Probably a stupid question but I would like to add multiple tables. I still only need one Domain Service, correct? Also, do I only mark one of the
    IQueryables<>
    with the
    IsDefault=true
    or do I need to do it for each table?

    Thanks,
    1) Yes
    2) No

    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    27 Jun 2011 10:46 AM
    Thanks Michael,
    for clarification....
    No to "mark only one" or No to "do it for each table".
    I am assuming I only mark 1...
    Sa souvraya niende misain ye!
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    27 Jun 2011 10:59 AM
    Posted By Refracted Paladin on 27 Jun 2011 10:46 AM
    Thanks Michael,
    for clarification....
    No to "mark only one" or No to "do it for each table".
    I am assuming I only mark 1...


    Ack!

    You caught my mistake. You have to have one query markes as default that does not take any parameters for each return type (table)
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    27 Jun 2011 11:15 AM
    Got it!

    Is there any logic to splitting out a large legacy database into multiple Entity's? I am new to Entity Framework an as such unsure whether it is "acceptable" to have 60 tables in one .edmx
    Sa souvraya niende misain ye!
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    27 Jun 2011 11:22 AM
    Is there any logic to splitting out a large legacy database into multiple Entity's? I am new to Entity Framework an as such unsure whether it is "acceptable" to have 60 tables in one .edmx


    I am not an expert with EF. I mostly use Linq to SQL and it can handle hundreds of tables.
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    28 Jun 2011 07:46 AM
    I am at a loss. I, believe, I have followed these directions to the letter. I even wiped the slate clean and started over but still no go. What I am getting is, at runtime, a red X in place of my data that states "Unable to load data. Please check your network connection and try again.". Any guesses as to what I am missing? For reference here is my Connection String
        <add name="ConnectEntities" connectionString="metadata=res://*/ConnectDatabase.csdl|res://*/ConnectDatabase.ssdl|res://*/ConnectDatabase.msl;provider=System.Data.SqlClient;provider connection string="data source=WWCSQL;initial catalog=Connect;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
     
    Sa souvraya niende misain ye!
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    28 Jun 2011 08:23 AM
    I am at a loss. I, believe, I have followed these directions to the letter. I even wiped the slate clean and started over but still no go.

    Please download the code samples on this site and see if they work for you.
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    28 Jun 2011 08:41 AM
    Just any code sample? I don't see one specific to this post but I will try a few others. I was also able to make this work connecting straight to the same database right in the LightSwitch Project.
    Sa souvraya niende misain ye!
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    28 Jun 2011 08:48 AM
    The RIA Services POCO Sample works as expected. The Print SQL Server Reports Samlpe works except when I try and Print Invoice though now that I look at it I am guessing I need the Website Sample that looks bundled with it for that portion.
    Sa souvraya niende misain ye!
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    28 Jun 2011 08:54 AM
    Just any code sample?

    on the Downloads page ( http://lightswitchhelpwebsite.com/D...loads.aspx ) please download:
    ■Integrating Visual Studio LightSwitch Application Into An Existing Website using IFrames (DNNThingsForSaleFinal.zip)
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    28 Jun 2011 09:10 AM
    It fails trying to load the data at this part:
    var UserInRole = (from DNNUser in WorkSpace.DNNDomainServiceData.vw_UserRoles
                                      where DNNUser.Username == UserName
                                      where DNNUser.RoleName == "Administrators"
                                      select DNNUser).FirstOrDefault(); 

    With the exception of ]Underlying Provider failed to Open
    Sa souvraya niende misain ye!
    Michael WashingtonUser is Offline
    Send Private Message
    Posts:1110
    Avatar

    --
    28 Jun 2011 09:53 AM
    It fails trying to load the data at this part:

    Oh darn I forgot you have to have a DotNetNuke site to connect to. That was a bad example.

    The POCO example is the best example. That is why I did that example, it shows how the WCF RIA Services work. Any other problems and they aspecificfic configuration issues that are impossible to figure out in a forum

    And I would not be able to look at your specific example because I must turn down requests for personal assistance because I would never be able to get any other work done
    -----------
    Michael Washington
    http://LightSwitchHelpWebsite.com
    Refracted PaladinUser is Offline
    New Member
    New Member
    Send Private Message
    Posts:9
    Avatar

    --
    28 Jun 2011 10:03 AM
    Understand completely, thanks for the help. I will continue to play around with it. If I figure it out I will post the solution here for reference.
    Sa souvraya niende misain ye!
    You are not authorized to post a reply.
    Page 1 of 3123 > >>


    Latest Microsoft Visual Studio LightSwitch Forum Threads That Have Answers

    All, I have a LightSwitch project that successfully published to Azure at least 30 times. I am getting a publish error. (I've already done Dave's bankruptcy process.) Unfortunately, this is the 2nd time I've received this error. The first time was after installing vs2013 Update 3. That time, I resolved the matter by uninstalling update 3. This time, I need something in Update 4 which I've just installed but unfortunately, I am getting the following error when publishing to Azure: ----------------------------------------------------------------------- Error 1 The "CSPack" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files
    Read more...

    HTML Client Add Record to Table
    11/23/2014 8:11 AM
    I have a quotes table and a quotes screen to view details about that quote.  I have a button that on execute would add a record to another table.  Call it QuoteEmailed. I have been looking at this site: http://lightswitchhelpwebsite.com/Blog/tabid/61/EntryId/1195/Dynamically-Creating-Records-In-The-LightSwitch-HTML-Client.aspx as well as this: http://msdn.microsoft.com/en-us/library/jj635144.aspx but have been unable to get the record to be added into the QuoteEmailed table. My code is so far is this but no errors but also no data entered into my SQL Azure datatable: myapp.ViewQuote.EmailQuote_execute = function (screen) { // Write code here. var newQuoteEmail = new myapp.sp_QuoteEmailInsert(); newQuoteEmail.QuoteID = screen.Quote.QuoteID; newQuoteEmail.RequestedDate = "Now"; alert(screen.Quote.QuoteID); return myapp.activeDataWorkspace.ApplicationData.saveChanges; alert(screen.Quote.QuoteID); }; The above was with
    Read more...

    We have a fairly dated Lightswitch application that we want to add an additional screen with data from a table that was recently added so we need to add that table to the Lightswitch data configuration (via right-clicking on the data source in the Solution Explorer, and selecting "Update Datasource").  However, the table that we recently added doesn't show up to be selected (ie, checkbox), but we do see the new table when we expand the database in the Data Connections in the Server Explorer (which we can also view rows from that table).  Any idea what we need to do to be able to get that new table into the Lightswitch datasource/data objects?
    Read more...

    Dear All, I created an application which collect data from our Database and provide it for the user. My question is, is there is a way that I can see how many users have used my app. I just want to see for example who logged in today in my application. If this possible, would you please provide me with some details how to use it. I can imagine that this can be done, but how ? my C# skills are lets say 6 month old :) I am using Light switch 2010 with C# code: Thansk a lot, Zayed
    Read more...

    Hi Everyone, The question in the title is very clear, in other way I want to hide the "Days" field in the Date picker because in my tables I only need months and years. Thank you
    Read more...

    1234
    Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation