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:1141
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:1141
    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:1141
    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:1141
    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:1141
    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:1141
    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:1141
    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:1141
    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:1141
    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

    Good morning to everyone, I'm getting frustrated with this error message "An exception occured when building the database for the application. Could not generate the deployement script." when deploying the lightswitch app. It only popups when it comes to the last step of publishing. It happens in the Microsoft.Lightswitch.Publish.targets file, that I've never touched before. See the image in full size Thank you in advance, Anas,
    Read more...

    HTML Grid Row Color
    12/16/2014 11:28 AM
    Using the HTML table, I'm trying to apply a background color to certain rows based on a value in one of the columns.  I'm using Rohit Agrawal's approach in his blog post, Spice Up Your HTML Client UI With Code.   Basically I'm setting the css background attribute for the row element to the desired color.  The problem I am having is that there is a default alternating row color  being applied of a very light grey.  That is overriding the red color I am trying to set.  In the screen shot below, the first two rows should be colored.  The second row is fine, because it normally does not have a background color due to an alternating row.  The first row, however, is not being colored as desired.  The alternating light grey color is overriding the color I am setting.  Does anyone have any help or insight into this issue?   Thank you, Binu Agrawal 
    Read more...

    Hi, The LS team stopped short of enabling runtime dynamic OData connections, so I thought I'd take a stab at it.  Turns out we can change the Odata Uri at runtime using an event handler for BuildingRequest method of the DataServiceContext.  The following code works to change the Uri at runtime.  Imports System.Data.Services.Client Imports LightSwitchApplication Namespace ApplicationData.ApplicationDataService Partial Public Class ApplicationData Inherits Global.System.Data.Services.Client.DataServiceContext Private Sub OnContextCreated() AddHandler Me.BuildingRequest, AddressOf OnBuildingRequest AddHandler Me.SendingRequest2, AddressOf OnSendingRequest2 End Sub Private Sub OnBuildingRequest(sender As Object, buildingRequestEventArgs As BuildingRequestEventArgs) Dim stUri As String = buildingRequestEventArgs.RequestUri.ToString stUri = Replace(stUri,
    Read more...

    Angularjs in Lightswitch HTML
    12/13/2014 5:59 PM
    I've tried to implement Jan Van Bladels article http://app.pragmaswitch.com/CrudGrid/ng-app/index.html and unlike other articles I have seen this one doesn't seem to involve mvc and app_start and so on, everything is done client side? I am able to access the index.html file at http://localhost:somenumber/HTMLClient/ng-app/index.html If I click the HTML client, I am redirected to the LS Browse screen I set up. There I have one post that I made in the LS client. However I can't seem to get this to show in the custom index.html file? If I click Add, nothing happens no modal window sliding down(guess I must make some .html file for this?), but the save button turns red, if i click this I get an error message saying "An error occured. Cannot read property 'extend' of undefined" However it is saved to the db, but as a blank post. I have uploaded the project to OneDrive https://onedrive.live.com/redir?resid=48547E6FC0593A30%21434 If anyone please could take a look at
    Read more...

    When I link a SharePoint Document Library (on Office 365 / SharePoint Online dev site, same host web as Cloud Business App), I receive the error "Error retrieving document library information" when I try to add a document while running the app in debug mode (comes up as an ajax dialog while I'm in the app). I see the Add Documents button, and when I click it, I get the Word / Excel / PowerPoint / Upload flyout menu, but receive the other error after awhile (30 or more seconds later) when I click one of those four options. Has anyone else seen this before? I  have verified my permissions to the document library. The connections seem to be set up fine, and the GUID column in the source (SQL Azure DB) and the document library (external) are properly related (one SQL entry-to-many Documents). The GUID column in the parent data source is properly populated and displayed.
    Read more...

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