Silverlight 4 Domainservice问题

时间:2011-02-14 08:41:50

标签: silverlight silverlight-4.0

为什么具有复杂类型参数的DomainService方法(除了int,bool,float,...之外的所有类型)在模型中都不可识别? 在构建甚至在知识分子! :(

更新

CODE

namespace KhorasanMIS.Web.Services
{
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.ComponentModel.DataAnnotations;
  using System.Data;
  using System.Linq;
  using System.ServiceModel.DomainServices.EntityFramework;
  using System.ServiceModel.DomainServices.Hosting;
  using System.ServiceModel.DomainServices.Server;
  using KhorasanMIS.Web.Entities;



  // Implements application logic using the KhorasanMISEntities context.
  // TODO: Add your application logic to these methods or in additional methods.
  // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
  // Also consider adding roles to restrict access as appropriate.
  // [RequiresAuthentication]
  [EnableClientAccess()]
  public class DSCountry : LinqToEntitiesDomainService<KhorasanMISEntities>
  {

    // TODO:
    // Consider constraining the results of your query method.  If you need additional input you can
    // add parameters to this method or create additional query methods with different names.
    // To support paging you will need to add ordering to the 'Countries' query.
    public IQueryable<Country> GetCountries()
    {
      return this.ObjectContext.Countries;
    }

    public IEnumerable<Country> GetCountryByCode(string pCode)
    {
      return this.ObjectContext.Countries.Where(a => a.ISOCode.Equals(pCode));
    }


    public bool IsValidEdit(string pCode)
    {
      List<string> message = new List<string>();
      IEnumerable<Country> list = GetCountryByCode(pCode);
      if (list.Count() > 0)
      {
        return false;
      }      
      return true;
    }

    //***********************************************************
    public bool Update(Country currentItem)
    {
      this.ObjectContext.Countries.AttachAsModified(currentItem, this.ChangeSet.GetOriginal(currentItem));
      return true;
    }
    //***********************************************************


  }
}

星号评论中的方法不能在模型中使用,但如果我将其参数更改为int,它将变为可用。

1 个答案:

答案 0 :(得分:0)

查看DomainServices的文档。插入,更新和删除操作由客户端的EntitySet和SubmitChanges方法处理。

  

当您公开域服务时,将在域上下文中生成EntitySet对象,该对象具有指示允许从客户端执行哪些操作(插入,更新或删除)的属性。您可以通过修改实体集合然后调用SubmitChanges方法来执行数据修改。