Dynamics CRM 2011编程系列(57):使用Business Connectivity Services 集成Sharepoint 2010 (中)

  接着上文,我们来看看步骤2),步骤3)和步骤4)的实现。

BCS项目的创建

  

图1

图2

图3

图4

图5

图6

 

BCS项目代码
    public partial class Entity1
    {
        //TODO: Implement additional properties here. The property Message is just a sample how a property could look like.
        public string Number { get; set; }
        public string Name { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
        public string Address { get; set; }
    }
}

 /// <summary>
    /// All the methods for retrieving, updating and deleting data are implemented in this class file.
    /// The samples below show the finder and specific finder method for Entity1.
    /// </summary>
    public class Entity1Service
    {
        private static CRMSVC.ICURD svc = CreateSVC();

        /// <summary>
        /// This is a sample specific finder method for Entity1.
        /// If you want to delete or rename the method think about changing the xml in the BDC model file as well.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Entity1</returns>
        public static Entity1 ReadItem(string id)
        {
            //TODO: This is just a sample. Replace this simple sample with valid code.
            CRMSVC.Account tmp = svc.GetAccount(id);
            return new Entity1() { Number=tmp.Number, Name=tmp.Name, Phone=tmp.PhoneNumber, Email=tmp.Email, Address=tmp.Address};
        }
        /// <summary>
        /// This is a sample finder method for Entity1.
        /// If you want to delete or rename the method think about changing the xml in the BDC model file as well.
        /// </summary>
        /// <returns>IEnumerable of Entities</returns>
        public static IEnumerable<Entity1> ReadList()
        {
            //TODO: This is just a sample. Replace this simple sample with valid code.
            List<Entity1> tmp=svc.GetAllAccount().Select<CRMSVC.Account, Entity1>(item => new Entity1() { Number = item.Number, Name = item.Name, Email=item.Email, Phone=item.PhoneNumber, Address=item.Address}).ToList();
           
            return tmp.ToArray();
           
        }

        private static CRMSVC.ICURD CreateSVC()
        {
            EndpointAddress endpoint = new EndpointAddress("http://your server name: your port number/CURD.svc");
            BasicHttpBinding binding = new BasicHttpBinding();
            ChannelFactory<CRMSVC.ICURD> svcFactory = new ChannelFactory<CRMSVC.ICURD>(binding, endpoint);
            return svcFactory.CreateChannel();
        }

        public static Entity1 CreateAccount(Entity1 InputAccount)
        {
            svc.CreateAccount(new CRMSVC.Account() { Number=InputAccount.Number, Name=InputAccount.Name, Address=InputAccount.Address, Email=InputAccount.Email, PhoneNumber=InputAccount.Phone});
            return InputAccount;
        }

        public static void Update(Entity1 InputAccount)
        {
            svc.UpdateAccount(new CRMSVC.Account() { Number = InputAccount.Number, Name = InputAccount.Name, Address = InputAccount.Address, Email = InputAccount.Email, PhoneNumber = InputAccount.Phone });
        }

        public static void Delete(Entity1 InputAccount)
        {
            svc.DeleteAccount(new CRMSVC.Account() { Number = InputAccount.Number, Name = InputAccount.Name, Address = InputAccount.Address, Email = InputAccount.Email, PhoneNumber = InputAccount.Phone });
        }

    }

小结

 1. BCS模型扩展的方法需要加上方法绑定(instances)。

 2. 输入参数与输出参数的typedescriptor需要与BCS实体的属性一致,否则同步后的数据将会丢失该属性的数据。

 

源码下载

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值