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 05: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:1023
Avatar

--
11 Jun 2011 05: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 12:25 PM
    Thanks for doing this.

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

    --
    15 Jun 2011 12: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:1023
    Avatar

    --
    15 Jun 2011 02: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 03: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:1023
    Avatar

    --
    26 Jun 2011 05: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 09: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:1023
    Avatar

    --
    27 Jun 2011 09: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 09: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:1023
    Avatar

    --
    27 Jun 2011 09: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 10: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:1023
    Avatar

    --
    27 Jun 2011 10: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 06: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:1023
    Avatar

    --
    28 Jun 2011 07: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 07: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 07: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:1023
    Avatar

    --
    28 Jun 2011 07: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 08: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:1023
    Avatar

    --
    28 Jun 2011 08: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 09: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

    Dear All, Iam new to C#, I almost worked for 2 month with C#. I need a help with the follwoing code. public partial class Part_2_CustomerItemDetail { partial void PDF_Execute() { vw_CustLedgerEntryItem1 entryItem = this.vw_CustLedgerEntry.SelectedItem; InvGetPDF2RequestBody reqBody = new InvGetPDF2RequestBody( entryItem.Document_No_ , Int16.Parse(entryItem.Report_Type) , "DynNavHRS" , @"\\p-nav-as-1\NavUserTemp\tma04" , false , false , "DE" , false , "" , "" , entryItem.Company , 1 , false); InvGetPDF2Request req = new InvGetPDF2Request(reqBody); HRSReportServiceSoapClient wsHRS = new HRSReportServiceSoapClient(); wsHRS.InvGetPDF2Completed += new
    Read more...

    Good morning everyone, Background So before, I used to have a SBS 2011 server which died. I only really used it for Exchange so signed up for an Office 365 Business account and retired the old server. I decided to take the opportunity to reinstall my laptop and dev machine to take advantage of Win 8.1 update 1 at this time. What now? Since the reinstall on both machines my LS projects (all out of browser) just stop at a blank screen. I'm guessing that it's something to do with the extensions I use but I know I'm using the right DevExpress install as my subscription expired and obviously haven't downloaded an new version since. I'm not sure about my C1 so downloaded the latest install and installed that presuming things would be ok. However, as mentioned, things aren't ok. All my previous LS projects build ok but load to a blank screen. Can anyone give an debugging / solutions to what to do? Thanks for reading. Paul.
    Read more...

    Hi, I have a RIA service that fills this class. Public Class RIAProjectValue <Key(), Editable(False)> _ Public Property Id As Integer Public Property ProjNum As String Public Property StartDate As DateTime? Public Property EndDate As DateTime? Public Property GrossVal As Decimal? Public Property TotalSub As Decimal? Public Property PercentSub As Decimal? End Class This is the default query which works fine. <Query(IsDefault:=True)> Public Function GetProjectValues() As IQueryable(Of RIAProjectValue) Return From p In Me.Context.ProjectValues Select New RIAProjectValue With { .Id = p.Id, .ProjNum = p.ProjNum, .StartDate = p.StartDate, .EndDate = p.EndDate, .GrossVal = If(p.GrossVal, 0), .TotalSub = 0,
    Read more...

    how to copy file from resource lightswitch project to a other directory (after publish 2 tier to install pc) ? Help me, Tks !
    Read more...

    I had a customer with an interesting question.  His LS app has a 'Browse Customers' screen which shows a list of customers in it. He raised the point that when on that screen someone new to the app could easily mistake the Metro interface's back arrow next to the 'Browse Customers' title to mean that you have to click it to go to the Browse Customers screen, even though you're on the screen.  I never noticed that, I'm so used to the UI, but he's got a point.  Is there a way to position the title to the right a bit more so as to limit confusion? Likewise in the screen's command bar we've added the prototypical add/edit buttons.  Doing so positions them on the lower-right of the screen.  Is there a way to position those elsewhere, say on top right?  Again, the client thinks it would be easier to see them on the top. I'm sure all this can be done with some custom CSS but wasn't sure if there was a better way.
    Read more...

    1234

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