This project is read-only.

Lookup Entities

Jul 23, 2010 at 2:24 PM

Hi,

First of all I would like to thank you for this toolkit!

My question is as follows:

Is there any way to automatically fill a lookup entity within an entity class using the class?

 

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Web.Services.Protocols;
using Streamsol.Crm;
using Streamsol.Crm.XrmDevelopmentToolkit;
using Microsoft.Crm.Sdk.Metadata;
using Microsoft.Crm.Sdk.Query;



namespace iBudget.Entities
{
    /// <summary>
    /// Approved Service entity stores data about services approved for consumer
    /// </summary>
    [XrmEntity("ibg_consumerapprovedservice")]
    public class ApprovedService : IXrmEntity
    {
        /// <summary>
        /// Primary key for ibg_consumerapprovedservice
        /// </summary>
        [XrmFieldMapping("ibg_consumerapprovedserviceid")]
        public Guid Id { get; set; }

        /// <summary>
        ///
        /// </summary>
        [XrmFieldMapping("ibg_begindate")]
        public DateTime Begindate { get; set; }

        /// <summary>
        /// The name of the custom entity.
        /// </summary>
        [XrmFieldMapping("ibg_consumerapprovedservicename")]
        public string Consumerapprovedservicename { get; set; }

        /// <summary>
        /// Unique identifier for Consumer associated with Approved Service.
        /// </summary>
        [XrmFieldMapping("ibg_consumerid")]
        public Guid Consumerid { get; set; }

        /// <summary>
        ///
        /// </summary>
        [XrmFieldMapping("ibg_enddate")]
        public DateTime Enddate { get; set; }

        /// <summary>
        /// Unique identifier for Service Code associated with Approved Service.
        /// </summary>
        [XrmFieldMapping("ibg_servicecodeid", CrmType = AttributeType.Lookup)]
        public Guid Servicecodeid { get; set; }

    }
}

For example here Servicecodeid is a lookup for this approvedservice entity within CRM. Is there any way I can fill the details of the Service Code using the toolkit else I have to query the ServiceCode entity using it's Guid to get further details.

Hope I am clear!

Cheers & Thanks!

Jul 28, 2010 at 12:27 AM

Hi Again,

 

I must apologise for the delay on these responses. I believe I understand what you are after. If you specify a Lookup, then I believe (as I don't have the source code in front of me) you can use the XrmReference type instead of GUID. this should give you more details. Note: If you are using Sql and filteredviews to query your data, then you just have to specify the attributename and it should populate all three (id, type and typecode).

There is an example here which maps to a customer (that's why it expects the XrmReferenceTypeAttribute, in most cases you won't need this):

http://xrm.codeplex.com/documentation

I will double check the source code tonight to confirm my answer.

Hope that helps,

Kurt