locked
WCF RIA - Not able to Add / Edit Entity (2013 HTML) RRS feed

  • Question

  • I have successfully managed to read the data from a WCF RIA Service, but if I try to show a Add Edit screen, everything is grey. I have a primary key on the table. I have seen different tutorials, where you need to add your own logic for adding, updating and delete data, but how does this really work and how do LightSwitch know which method to be choosen? Need some help here. 
    • Edited by Phero_ Tuesday, September 8, 2015 1:44 PM
    Monday, September 7, 2015 2:03 PM

Answers

  • Hello

    For anything WCF RIA related there is only one place to go. Check out www.lightswitchhelpwebsite.com and especially the combining two tables blog post. Read the whole thing as it is useful, or skip to about 1\2 way and see the Updating Records in a WCF RIA service part.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by ADefwebserver Monday, September 7, 2015 10:06 PM
    • Marked as answer by Angie Xu Thursday, September 17, 2015 9:21 AM
    Monday, September 7, 2015 3:47 PM
  • I would recommend following this tutorial to the letter and then see if you still have the same issue.

    http://lightswitchhelpwebsite.com/Forum/tabid/63/aft/89/Default.aspx


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by Otis Ranger Tuesday, September 8, 2015 1:31 PM
    • Marked as answer by Angie Xu Thursday, September 17, 2015 9:21 AM
    Tuesday, September 8, 2015 1:31 PM

All replies

  • Hello

    For anything WCF RIA related there is only one place to go. Check out www.lightswitchhelpwebsite.com and especially the combining two tables blog post. Read the whole thing as it is useful, or skip to about 1\2 way and see the Updating Records in a WCF RIA service part.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by ADefwebserver Monday, September 7, 2015 10:06 PM
    • Marked as answer by Angie Xu Thursday, September 17, 2015 9:21 AM
    Monday, September 7, 2015 3:47 PM
  • Monday, September 7, 2015 10:08 PM
  • The code below works (read). I have choosen a bit different path here and I wonder how you could write the update / insert logic based of the GetAllComments. 

    Should you be able to use the ordinary addnewedit method based on a button? In this case, the button is invisible. 

    [Query(IsDefault = true)]
            public IQueryable<Comments> GetAllComments()
            {
    
                using (Entities dbContext = new Entities())
                {
                   
                    List<Comments> result = new List<Comments>();
                    var commentList = dbContext.COMMENT;
                    foreach (var item in commentList)
                    {
                        Comments newEntity = new Comments
                        {
                            KEY = item.KEY,
                            TYPE = item.TYPE,
                            SEQ_NO = item.SEQ_NO,
                            COMMENT = item.COMMENT,
                            CREATED_BY = item.CREATED_BY,
                            CREATED_DATE = item.CREATED_DATE.Value,
                            AMENDED_BY = item.AMENDED_BY,
                            AMENDED_DATE = item.AMENDED_DATE.Value
                            
                        };
                        result.Add(newEntity);
                    }
                    return result.AsQueryable();
                } 
    
            }

    Tuesday, September 8, 2015 8:44 AM
  • I cannot stress enough that you need to read the articles that have been suggested to you. If you are unsure on any of it then download the sample projects that Michael has done and this will show you the code parts in context. Following his tutorials will give you the knowledge that you need to change his test scenario into something that you can use in your own project.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, September 8, 2015 9:06 AM
  • Otis, 

    The tutorials are not applicable in this case, because I am not using any intrinisic database. I am loading data from ADO.NET (Oracle), because there is bug in the ODP.NET provider - which is pretty old and that's why I am struggling with the WCF RIA service.

    I have been trying to use the logic provided by Michael, by simply name the method with UpdateXXX followed by the class name as input, but nothing happends. I can't update at all. If I set the screen which is a AddEdit screen to be a home screen, I am able to see the fields, but everything is grey.

    But I am able to read the data and put the result into a browse screen! 

    Tuesday, September 8, 2015 10:55 AM
  • The whole point in using the WCF RIA service is that you can connect to ANY datasource and Michael demonstrates this in his other posts (see connecting to a .csv file for an example). By just reading a couple of them I know that I can do the following code for an update:-

    public void UpdateComment(Comments commentRecord)
    
    {
    
    	var objResult = (from comment in dbContext.COMMENT
    					 where comment.KEY == commentRecord.KEY
    					 select comment).FirstOrDefault();
    
    	if (objResult != null)
    	{
    		objResult = commentRecord;
    	}
    
    }
    This isn't the complete code and it isn't tested but I know that this is along the right lines of what to do.
    Copy and paste may be a laugh but knowledge will be a friend for life.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, September 8, 2015 11:34 AM
  • Otis,

    Yes. I have done something similiar, but the screen is grey. I guess it should be enough to declare:

    public void UpdateComment(Comments commentRecord)
    
    {
    
    }

    and the screen should be updatable (the fields would be editable?)

    Please note that I am using ADO.NET Entity Data Model


    • Edited by Phero_ Tuesday, September 8, 2015 12:37 PM
    Tuesday, September 8, 2015 12:23 PM
  • If the code started with Update and you refreshed the data source afterwards then it should be enough....although you may need a Create one as well for the AddEdit button\screen to be active.

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, September 8, 2015 12:39 PM
  • I have been using parts of the following tutorial: How to Use WCF RIA Service in LightSwitch 2012 

    But I have excluded step 7, to add a Domain Service Class, but according to the tutorial you have some editable settings on the entity.

    When I added CreateComments, I am able to see the button to the AddEdit Screen, but nothing is happening when I am pressing the button. 
    • Edited by Phero_ Tuesday, September 8, 2015 1:09 PM
    Tuesday, September 8, 2015 1:04 PM
  • I would recommend following this tutorial to the letter and then see if you still have the same issue.

    http://lightswitchhelpwebsite.com/Forum/tabid/63/aft/89/Default.aspx


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by Otis Ranger Tuesday, September 8, 2015 1:31 PM
    • Marked as answer by Angie Xu Thursday, September 17, 2015 9:21 AM
    Tuesday, September 8, 2015 1:31 PM
  • I don't have the Domain Service Class to add .. that's the problem. 
    Tuesday, September 8, 2015 1:33 PM
  • What version of Visual Studio are you using?

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, September 8, 2015 1:36 PM
  • Visual Studio 2013 Pro
    Tuesday, September 8, 2015 1:37 PM
  • ok, follow Justin's answer in this blog post.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/d0ca8e9f-f4a6-4619-a18c-bd189c4469bb/add-wcf-ria-services-in-visual-studio-lightswitch-2013-rc?forum=lightswitch

    You can create a new domain service without using the project template fairly easily:

    • Create a Class Library project
    • Add a reference to System.ServiceModel.DomainServices.Server assembly
    • Make your class inherit from the DomainService class found in the System.ServiceModel.DomainServices.Server namespace.

    It seems it was removed in VS 2013 as detailed here (https://connect.microsoft.com/VisualStudio/feedback/details/791538/i-cannot-add-domainservice-class-in-visual-studio-2013)


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, September 8, 2015 1:55 PM
  • I have recreated the project and repeated all steps again, with success. No clue why this happend. Anyway, thanks for your time. 
    Wednesday, September 9, 2015 1:15 PM