Está viendo un tema de ayuda de Laserfiche Cloud. Si no está utilizando Laserfiche Cloud, consulte la Guía del usuario de Laserfiche o la Guía de administración de Laserfiche .
Consulte el siguiente código de ejemplo para obtener una demostración de cómo insertar una nueva instancia de un modelo de entidad. El código de ejemplo supone que la definición del modelo yaexiste.
En el ejemplo se supone que ya ha creado un objeto de sesión del SDK de entidades.
En este ejemplo, la definición del modelo contiene:
El código de ejemplo utiliza las clases siguientes:
private static void InsertData(Laserfiche.ProcessAutomation.Session session, BusinessEntityModelInfo mymodel)
{
string value1 = "Joe Laserfiche"; //This is the "column" value
BusinessEntityInstanceEditable instancedata = new BusinessEntityInstanceEditable();
//Retrieve the available "columns" defined in your model definition.
List<BusinessEntityModelMemberData> members = mymodel.Props.Members;
//Create an object to hold the values you want to insert.
List<BusinessEntityInstWriteMemberData> memberList = new List<BusinessEntityInstWriteMemberData>();
//Iterate through the defined "columns" of your model and specify the values you want to insert.
//In this sample, it is assumed that there is only 1 member defined.
foreach (BusinessEntityModelMemberData member in members)
{
BusinessEntityInstWriteMemberData mem = new BusinessEntityInstWriteMemberData()
{
MemberId = member.MemberId,
MemberName = member.MemberName,
MemberValue = value1,
};
memberList.Add(mem);
}
instancedata.BusinessUnitId = new Guid();
instancedata.MemberValues = memberList;
//Use a lambda expression to initiate the creation of the new instance of the model.
System.Threading.Tasks.Task.Run(async () =>
{
BusinessEntityInstanceInfo instanceInfo = await BusinessEntityInstances.CreateAsync(mymodel.Id, instancedata, session);
}).Wait();
}
En el ejemplo siguiente se muestra cómo crear una nueva instancia de un modelo que incluye la creación de un vínculo de miembro de referencia a una instancia de otro modelo.
private static void InsertData(Laserfiche.ProcessAutomation.Session session, BusinessEntityModelInfo mymodel)
{
BusinessEntityInstanceEditable instancedata = new BusinessEntityInstanceEditable();
List<BusinessEntityModelRefMemberData> refmembers = mymodel.Props.ReferenceMembers;
//This sample does not show inserting member values, so leave this memberList object empty.
List<BusinessEntityInstWriteMemberData> memberList = new List<BusinessEntityInstWriteMemberData>();
List<BusinessEntityInstWriteRefMemberData> refMemberList = new List<BusinessEntityInstWriteRefMemberData>();
foreach (BusinessEntityModelRefMemberData refmember in refmembers)
{
//In this sample, the code iterates through the instances of a reference member model and assign the first instance
//as the reference member value.
List<BusinessEntityInstanceInfo> refmemberinstance = BusinessEntityInstances.EnumAllAsync((Guid)refmember.ToEntityId, session).Result.ToList();
//This EntityReferenceMemberValueEntity points to the instance ID and model ID
//of the first instance of the "other" model.
EntityReferenceMemberValueEntity refinstance = new EntityReferenceMemberValueEntity()
{
EntityInstId = refmemberinstance[0].Id,
EntityModelId = (Guid)refmember.ToEntityId
};
BusinessEntityInstWriteRefMemberData refMemberData = new BusinessEntityInstWriteRefMemberData()
{
FromEntityId = refmember.FromEntityId,
FromMemberId = refmember.FromMemberId,
FromMemberName = refmember.FromMemberName,
ToEntityId = refmember.ToEntityId,
ToMemberId = refmember.ToMemberId,
ToMemberName = refmember.ToMemberName,
RelationshipId = refmember.RelationshipId,
RelationshipType = refmember.RelationshipType,
ReferenceOthersideInst = new List<EntityReferenceMemberValueEntity>() { refinstance },
};
refMemberList.Add(refMemberData);
}
instancedata.MemberValues = memberList;
instancedata.ReferenceMemberValues = refMemberList;
//Use a lambda expression to initiate the creation of the new instance of the model.
System.Threading.Tasks.Task.Run(async () =>
{
BusinessEntityInstanceInfo instanceInfo = await BusinessEntityInstances.CreateAsync(mymodel.Id, instancedata, session);
}).Wait();
}