Alternative to Using an Entity as a Parameter to an Invoke Method in WCF RIA Services

后端 未结 2 514
旧时难觅i
旧时难觅i 2021-01-12 11:48

Howdy, ya\'ll! First question on StackOverflow! :-)

So here\'s the scenario: We\'re working on a web app with Silverlight 4 and using WCF RIA Services 1.0 SP1 Beta f

相关标签:
2条回答
  • 2021-01-12 12:22

    Many thanks to Mr. Jeff Handley and Mr. Dinesh Kulkarni for the answer (through Twitter).

    In order for an Entity to be used as a parameter in an invoke method, that Entity must be exposed through a query method existing within the same DomainService. The intention for this restriction is that

    "Each domain service needs to be able to stand on its own."

    By adding two dummy Query methods (see Jeff's answer for an example), I was able to compile my code.

    0 讨论(0)
  • 2021-01-12 12:26

    I have the following and it works for me.

    namespace BusinessApplication2.Web
    {
        using System.ComponentModel.DataAnnotations;
        using System.Linq;
        using System.ServiceModel.DomainServices.Hosting;
        using System.ServiceModel.DomainServices.Server;
    
        [EnableClientAccess()]
        public class DomainService1 : DomainService
        {
            public IQueryable<EntityOne> GetEntityOnes()
            {
                return null;
            }
    
            public IQueryable<EntityTwo> GetEntityTwos()
            {
                return null;
            }
    
            [Invoke]
            public SerializableResult GetSerializableResult(EntityOne one, EntityTwo two)
            {
                return new SerializableResult() { Result = "It woooooorrrked!" };
            }
        }
    
        public class EntityOne
        {
            [Key]
            public int Id { get; set; }
        }
    
        public class EntityTwo
        {
            [Key]
            public int Id { get; set; }
        }
    
        public class SerializableResult
        {
            public string Result { get; set; }
        }
    }
    
    0 讨论(0)
提交回复
热议问题