Custom Entity Code

Anything created with the Custom Entity Auto-Code Designer is capable of having that design exported into actual c# code for you to add to your own .net library that can be loaded as an Add-In [see more] in LemonEdge.

Code

The Auto-Code Designer will export the following:

  • The interface for your Custom Entity with all the associated LemonEdge attributes depending on your custom entity design
    • You can modify any part of this interface. 
  • The actual class that implements this interface for your custom entity.
    • There are partial methods for you to hook into all the properties on the implemented class should you wish to.
    • You can modify any part of this class, or create your own that implements the interface. There is a LemonEdge tool which will auto-create classes for you that implement the LemonEdge interface. This way should you make changes to the interface in code the system can still regenerate your class for you.

See our API-Code section for more information about using our API to create you own entities.


Example

As a simple example, if you create an Custom Entity called "Insurance Contract" that had a Name, Description and CurrencyID link as properties the system would create the following code for you:

/*

Auto Generated file by LemonEdge © 2020
Warning: Any changes to this file will be overwritten if it is regenerated.

*/

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Text;
using LemonEdge.Entities;
using LemonEdge.API.Core;
using LemonEdge.API.Entities;
using System.Linq;
using System.Threading.Tasks;
using System.Reflection;
using LemonEdge.Core;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Runtime.Serialization;
using LemonEdge.API.Attributes;

namespace LemonEdge.Entities
{



	[EntityDefinition("057f0323-a505-4c6a-a300-abdc00a558f8", "dbo.InsuranceContracts", "InsuranceContract", IsStandingDataEntity = false, LabelColumn = "Name", SetName = "InsuranceContracts")]
	[DefaultEntityIcon("00000000-0000-0000-0000-00000000004c")]
	public interface IInsuranceContract : 
		IBaseEntityWithPermissions
	{

		[EntityProperty(LemonEdge.Utils.Database.SQLType.NVarChar, 500, false, ColumnName = "Name")]
		[EntityKeyProperty]
		[System.ComponentModel.DataAnnotations.Required]
		String Name { get; set; }

		[EntityProperty(LemonEdge.Utils.Database.SQLType.UniqueIdentifier, false, ColumnName = "CurrencyID")]
		[LemonEdge.API.Attributes.Validation.RequiredNoDefaultIDValidation]
		[EntityRelationship("00000000-0000-0000-0000-00000000000f", "ID", LemonEdge.Utils.Database.SingleJoinType.One, "CurrencyID", "InsuranceContracts", InheritPermissions = false, DeleteWithRelationship = false, PartOfParentSet = false, LinkToItemInSet = false, PreventAutoConstraint = false)]
		Guid CurrencyID { get; set; }

		[EntityProperty(LemonEdge.Utils.Database.SQLType.NVarChar, 2000, true, ColumnName = "Description")]
		String Description { get; set; }

	}


	[DataContract]
	public partial class InsuranceContract : 
		LemonEdge.API.Core.BaseEntityWithPermissions, 
		IInsuranceContract,
		LemonEdge.Utils.Interfaces.ICloneableAsync
	{

		[DataMember]
		private String _name;
		[DataMember]
		private Guid _currencyID;
		[DataMember]
		private string _currencyID_Label;
		[DataMember]
		private String _description;

		[System.ComponentModel.DataAnnotations.Required]
		[System.ComponentModel.DataAnnotations.StringLength(500)]
		public String Name
		{
			get => _name;
			set
			{
				if(_name != value)
				{
					OnPropertyChanging(nameof(Name));
					_name = value;
					OnPropertyChanged(nameof(Name));
					OnNameChanged();
				}
			}
		}

		partial void OnNameChanged();

		[LemonEdge.API.Attributes.Validation.RequiredNoDefaultIDValidation]
		public Guid CurrencyID
		{
			get => _currencyID;
			set
			{
				if(_currencyID != value)
				{
					OnPropertyChanging(nameof(CurrencyID));
					_currencyID = value;
					OnPropertyChanged(nameof(CurrencyID));
					OnCurrencyIDChanged();
				}
			}
		}

		partial void OnCurrencyIDChanged();

		public String CurrencyID_Label
		{
			get => _currencyID_Label;
			set
			{
				if(_currencyID_Label != value)
				{
					OnPropertyChanging(nameof(CurrencyID_Label));
					_currencyID_Label = value;
					OnPropertyChanged(nameof(CurrencyID_Label));
					OnCurrencyID_LabelChanged();
				}
			}
		}

		partial void OnCurrencyID_LabelChanged();

		[System.ComponentModel.DataAnnotations.StringLength(2000)]
		public String Description
		{
			get => _description;
			set
			{
				if(_description != value)
				{
					OnPropertyChanging(nameof(Description));
					_description = value;
					OnPropertyChanged(nameof(Description));
					OnDescriptionChanged();
				}
			}
		}

		partial void OnDescriptionChanged();

		#region ICloneableAsync Implementation

		public void CopyFromSource(IInsuranceContract source) => CopyFromEntity(source);

		async Task LemonEdge.Utils.Interfaces.ICloneableAsync.Clone(object context) => (IInsuranceContract) await Clone(context);

		protected override void CopyFromEntity(IBaseEntity src)
		{
			base.CopyFromEntity(src);
			var source = (IInsuranceContract)src;
			_name = source.Name;
			_currencyID = source.CurrencyID;
			if(source is InsuranceContract s1) _currencyID_Label = s1.CurrencyID_Label;
			_description = source.Description;
			OnCloning(src);
		}

		partial void OnCloning(IBaseEntity src);

		#endregion


		public override string ToString() => Name;

	}

}


 

See our API-Code section for more information about using our API to create you own entities.