locked
Read Only Rows returning from WCF RIA Stored Procedure calls

    Question

  • Hi,

    From this example, http://blogs.msdn.com/b/lightswitch/archive/2010/12/16/how-to-create-a-many-to-many-relationship-andy-kung.aspx I have created three tables (Movie, Genre, MovieGenre). Now....

     

    And I followed these blog post for the rest... 

    http://www.tejana.com/Home/Blog/tabid/71/EntryId/15/Microsoft-LightSwitch-and-WCF-RIA-Services.aspx 

    http://www.tejana.com/Home/Blog/tabid/71/EntryId/16/Stored-Procedures-in-LightSwitch.aspx

     

    01. I have created a Stored Procedure that returns all Genres from Genre Table, and extra fields - GenreName from Genre Table & Boolean field with true/false value if a particular genre is selected on the MovieGenre Table, for a selected Movie. Example output would be

     

    MovieId, GenreId, GenreName, IsSelected

    1, 1, Action, True

    1, 2, Adventure, True

    NULL, 3, Crime, False

    NULL, 4, Suspense, False

     

    02. Now I created an WCF RIA project.  On the DomainService.CS file, I have created a Class named MovieGenre.

     

      public class MovieGenre
      {
        [Key]
        public int MovieId { get; set; }
    
        [Key]
        public int GenreId { get; set; }
    
        public string GenreName { get; set; }
    
        public bool IsSelected { get; set; }
    
        public static MovieGenre CreateNew(IDataRecord sDataReader)
        {
          return new MovieGenre { GenreId = (int)sDataReader["GenreId"], MovieId = 1, GenreName = (string)sDataReader["GenreName"], IsSelected = (bool)sDataReader["IsSelected"] };
        }
      }
    
    

     

    03. Created a Data Access Class with these methods.

        public static IEnumerable<MovieGenre> GenresByMovieId(int? MovieId)
        {
          SqlCommand sComm = new SqlCommand("Web.Genres_SelectGenresByMovieId");
          sComm.CommandType = CommandType.StoredProcedure;
          sComm.Parameters.AddWithValue("MovieId", MovieId);
    
          using (SqlConnection sConn = new SqlConnection(sConnString))
          {
            sComm.Connection = sConn;
            sConn.Open();
    
            SqlDataReader sDataReader = sComm.ExecuteReader();
            if (sDataReader.HasRows)
              while (sDataReader.Read())
                yield return MovieGenre.CreateNew(sDataReader);
            sConn.Close();
          }
        }
      }
    
        public static IEnumerable<MovieGenre> AllGenres()
        {
          // All of above except MovieId parameter
          // But this method will not be used for sure 
          // because always a parameter will be passed
        }
    
    

     

    04. This is my DomainService class.......

    public class RIADomainService : DomainService
      {
        [Query(IsDefault = true)]
        public IEnumerable<MovieGenre> SelectAllGenres()
        {
          return MovieGenreSource.AllGenres();
        }
    
        [Query]
        public IEnumerable<MovieGenre> SelectAllMovieGenre(int? mId)
        {
          return MovieGenreSource.GenresByMovieId(mId);
        }
    
        [Insert]
        public void CreateMovieGenre(MovieGenre mg)
        {
        }
    
        [Update]
        public void UpdateMovieGenre(MovieGenre mg)
        {
        }
    
        [Delete]
        public void DeleteMovieGenre(MovieGenre mg)
        {
        }
      }
    

    05. Finally............. when I add the above RIA method into my DATAGRID UI, it produces READ ONLY columns/rows.  

     

    Am I missing something here in order to edit the records and update them back to MovieGenre Table?  I didn't develop any INSERT code so far. But as per Tejana's post, I supposed to get a Read/Write Columns... isn't it?

     

    My ultimate goal for above implementation is to create Many-To-Many CheckedListbox/Grid control.... which I asked on of my previous post (http://social.msdn.microsoft.com/Forums/en/lightswitchgeneral/thread/0acaa406-61d5-4180-9a98-c23b644520f8).

     


    -Bala
    Tuesday, April 05, 2011 5:26 AM

Answers

  • novascape & Naveed,

    Thx for your reply. 

     

    @Naveed: Sorry abt the error code.  I didn't have the source when I post the message, so I typed all of them on the browser itself.  Indeed you are right that the code works fine.  

     

    However I found out the the problem that produced READ ONLY ROWS.  What I have done was..

     

    1. Get the Movie's List from a Data Source "MoviesData"

    2. Get the MovieGenre List from my above code (WCF RIA), named "MovieDomainServiceData"

     

    But the LS Screen takes only a single Data Source  with READ/WRITE permission and put the other Data Source READ ONLY.  To confirm this, I created Movie & Genre classes on the DomainService (WCF RIA) and created a Screen only with RIA Data Source.  Now my MovieGenre Grid became editable

     

    If this is by design (or known issue) supporting only one Data Source with READ/WRITE permission, then I'm just aware of this. Hope this helps someone else.

     

    Again thanks for your support. :)

     

    UPDATE :  Here is the answer for Enabling Multiple Data Sources in a single SCREEN. 

    http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/1ccd5fb6-1e1d-48d1-9b4c-e2c9628a3eb1

     


    -Bala


    • Marked as answer by PowerBala Tuesday, April 05, 2011 7:21 PM
    • Unmarked as answer by PowerBala Tuesday, April 05, 2011 8:22 PM
    • Edited by PowerBala Friday, April 08, 2011 2:36 AM Providing Solution Link
    • Marked as answer by PowerBala Friday, April 08, 2011 2:36 AM
    Tuesday, April 05, 2011 7:20 PM

All replies

  • Could it be because you're using a compound key on your link table? Maybe try adding just a single [Key] to the MovieGenre table.


    Xander
    Tuesday, April 05, 2011 8:45 AM
  • I created a new data source based on the code snippet that you provided. Everything worked fine on my end apart from a few compiler errors I fixed. Just to debug it a bit more, Can you start with a fairly simple RIA service, i.e. without any SQL stuff and see if that works. If it does, then you can add more code to your data source and see what causes the source to become readonly.

    Let me know if you are not able to fix this. It would also help if you copy/paste the exact code you have in your data source as the one above has some compiler errors.


    Naveed Zafar
    Tuesday, April 05, 2011 8:56 AM
  • novascape & Naveed,

    Thx for your reply. 

     

    @Naveed: Sorry abt the error code.  I didn't have the source when I post the message, so I typed all of them on the browser itself.  Indeed you are right that the code works fine.  

     

    However I found out the the problem that produced READ ONLY ROWS.  What I have done was..

     

    1. Get the Movie's List from a Data Source "MoviesData"

    2. Get the MovieGenre List from my above code (WCF RIA), named "MovieDomainServiceData"

     

    But the LS Screen takes only a single Data Source  with READ/WRITE permission and put the other Data Source READ ONLY.  To confirm this, I created Movie & Genre classes on the DomainService (WCF RIA) and created a Screen only with RIA Data Source.  Now my MovieGenre Grid became editable

     

    If this is by design (or known issue) supporting only one Data Source with READ/WRITE permission, then I'm just aware of this. Hope this helps someone else.

     

    Again thanks for your support. :)

     

    UPDATE :  Here is the answer for Enabling Multiple Data Sources in a single SCREEN. 

    http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/1ccd5fb6-1e1d-48d1-9b4c-e2c9628a3eb1

     


    -Bala


    • Marked as answer by PowerBala Tuesday, April 05, 2011 7:21 PM
    • Unmarked as answer by PowerBala Tuesday, April 05, 2011 8:22 PM
    • Edited by PowerBala Friday, April 08, 2011 2:36 AM Providing Solution Link
    • Marked as answer by PowerBala Friday, April 08, 2011 2:36 AM
    Tuesday, April 05, 2011 7:20 PM