生成的文件后缀名为.edmx,如本例中的RiaServiceModel.edmx
1.编译整个Solution。
2.再次在Web项目上右击,新增本文的主角——Domain Service Class Domain Service Class 。"Domain Service Class”这名字挺熟的吧?嗯,上文介绍过了。
根据提示勾选需要的部分。在本例中,我们选择了Messages表作为实体,并选择”Enable editing”,这样在生成的类中会初始包括Get,Insert,Update,Delete 4个基本的实体操作方法
完成上面的操作后,会在Web项目下生成RdChat_DomainService.cs类。
namespace RiaServices_1.Web
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Ria;
using System.Web.Ria.Data;
using System.Web.DomainServices;
using System.Data;
using System.Web.DomainServices.LinqToEntities;
// Implements application logic using the RdChatEntities context.
// TODO: Add your application logic to these methods or in additional methods.
[EnableClientAccess()]
public class RdChat_DomainService : LinqToEntitiesDomainService<RdChatEntities>
{
// TODO: Consider
// 1. Adding parameters to this method and constraining returned results, and/or
// 2. Adding query methods taking different parameters.
public IQueryable<Messages> GetMessages()
{
return this.Context.Messages;
}
public void InsertMessages(Messages messages)
{
this.Context.AddToMessages(messages);
}
public void UpdateMessages(Messages currentMessages, Messages originalMessages)
{
this.Context.AttachAsModified(currentMessages, originalMessages);
}
public void DeleteMessages(Messages messages)
{
if ((messages.EntityState == EntityState.Detached))
{
this.Context.Attach(messages);
}
this.Context.DeleteObject(messages);
}
}
}
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web.Ria;
using System.Web.Ria.Data;
using System.Web.DomainServices;
using System.Data;
using System.Web.DomainServices.LinqToEntities;
// Implements application logic using the RdChatEntities context.
// TODO: Add your application logic to these methods or in additional methods.
[EnableClientAccess()]
public class RdChat_DomainService : LinqToEntitiesDomainService<RdChatEntities>
{
// TODO: Consider
// 1. Adding parameters to this method and constraining returned results, and/or
// 2. Adding query methods taking different parameters.
public IQueryable<Messages> GetMessages()
{
return this.Context.Messages;
}
public void InsertMessages(Messages messages)
{
this.Context.AddToMessages(messages);
}
public void UpdateMessages(Messages currentMessages, Messages originalMessages)
{
this.Context.AttachAsModified(currentMessages, originalMessages);
}
public void DeleteMessages(Messages messages)
{
if ((messages.EntityState == EntityState.Detached))
{
this.Context.Attach(messages);
}
this.Context.DeleteObject(messages);
}
}
}
再次编译整个Solution。