IModelEntry<TModel> Interface
.NET Standard 2.x | Current Version (1.0.1)
Represents a object that contains the data of the TModel
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
Inheritance Constructor
Syntax
public interface IModelEntry<TModel>;
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
Controller Class: IModelEntryExampleController