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

    I'm trying to hide a button based on an user permission but the FindControl method below trips with error: "Cannot access a closed screen."  Any help on this would be appreciated! Private Sub Approve_CanExecute(ByRef result As Boolean) ' enable button based on user permission and when grid row is selected If Me.Permits.SelectedItem Is Nothing Then result = False Else result = (Application.User.HasPermission(Permissions.CanViewAllPermits)) And _ (Me.Permits.SelectedItem.Status = statusPending) End If ' hide Approve button Me.FindControl("Approve").IsVisible = result End Sub Private Sub Approve_Execute() If Me.ShowMessageBox("Are you sure you want to APPROVE this permit?", "Approve " +
    Read more...

    I have a LIghtswitch silverlight Out of Browser application that is hosted in Azure Websites.  Since it is out of browser, is there any advantage of having the "Free" vs "Shared" plan?  The only advantage I can see would be a Custom Domain with the "Shared".  But extra resources would not do anything for the application would it since it is hosted out of browser and install on the users desktop?  Or am I misunderstanding the Out of Browser? Thanks!
    Read more...

    Does LightSwitch  VS2013 Supports To Upload a File in Sql Server Without Using Any Silverlight or Azure or WCF Technology please let me know .
    Read more...

    Lightswitch Designer of VS 2013 Update 4 unable to read .lsml file created in VS2013 Update 3. Yves Pflieger
    Read more...

    I am trying to setup a simple database application for Lightswitch.  The data base is only four MSSQL tables (Contacts, Addresses, Emails and Phones).  When I add a screen I get three templates (Browse Data, View Details and Add/Edit) rather than the five or more templates shown in all the tutorials I've seen.  Building the solution gives the errors: Error 1 Source file 'C:\Users\Admin\Documents\Visual Studio 2013\Projects\Contacts\Contacts\Contacts.Server\GeneratedArtifacts\ContactsDataObjectContext.cs' could not be opened ('Unspecified error ') Contacts.Server Error 2 Could not copy the file "C:\Users\Admin\Documents\Visual Studio 2013\Projects\Contacts\Contacts\Contacts.Server\obj\Debug\Application.Server.dll" because it was not found. C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v4.0\Microsoft.LightSwitch.targets 103 10 Contacts What have I done wrong??  
    Read more...

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