IModelEntry Interface
.NET Standard 2.x
Represents an object that contains the data of a model object and the state of the data.
It provides methods, properties, and events for accessing and manipulating the data and state.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public interface IModelEntry;
Event
Name | Description |
---|---|
CurrentValueChanged | Occurs when the current value is changed. |
Property
Name | Returns Type | Description |
---|---|---|
ModelState | ModelState | Gets the tracked state of the data. |
Properties | int | Gets the property names of the model class. |
Method
Name | Returns Type | Description |
---|---|---|
GetPropertyState(string name) | PropertyState | Gets the tracked state of the specified property. |
GetOriginalValue(string name) | object | Gets the original value of the specified property. |
GetCurrentValue(string name) | object | Gets the current value of the specified property. |
SetCurrentValue(string name, object value) | void | Sets the current value for the specified property. |
Examples
The following code example demonstrates how to use IModelEntry
to get and set details for a student record which contains data and state.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.IModelEntryExamples
{
public class IModelEntryExample
{
private SchoolContext _context;
public IModelEntryExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example(IModelEntry<Person> student)
{
// Gets the model state.
Console.WriteLine("Model State: {0}",
student.ModelState.ToString());
// Gets the properties.
Console.WriteLine("Properties:");
foreach (var propertyName in student.Properties)
{
Console.WriteLine(propertyName);
}
// Gets the property state of Enrollment Date.
Console.WriteLine("Enrollment Date State: {0}",
student.GetPropertyState("EnrollmentDate").ToString());
// Gets the current value of Enrollment Date.
Console.WriteLine("Current Enrollment Date: {0}",
student.GetCurrentValue("EnrollmentDate"));
// Gets the original value of Enrollment Date.
Console.WriteLine("Original Enrollment Date: {0}",
student.GetOriginalValue("EnrollmentDate"));
student.CurrentValueChanged += ShowValueChanges;
// Sets Enrollment Date with a new value.
student.SetCurrentValue("Enrollment Date", new DateTime(2019, 1, 3));
/* The code produces the following output:
Model State: Modified
Properties:
PersonID
LastName
FirstName
HireDate
EnrollmentDate
Discriminator
Enrollment Date State: Modified
Current Enrollment Date: 1/2/2019 12:00:00 AM
Original Enrollment Date: 1/1/2019 12:00:00 AM
EnrollmentDate Changed to 1/3/2019 12:00:00 AM
*/
}
private void ShowValueChanges(string name, object value)
{
Console.WriteLine("{0} changed to {1}",
name, value);
}
}
}
Example Refer To
Model Class: Student