PropertyEnumerators For Entity Objects in LiteMDA

Source: Internet
Author: User

In LiteMDA, an ICondition parameter must be input for Load, Update, and Delete. ICondition contains the conditions used for query. For ORM, eventually it must be a combination of a group of sub-conditions, such as Condition. add ("User. name ", OP. equals, "teddy"). What is the problem with such a statement? Mainly, You need to manually enter the condition Name. If you mistakenly enter a Name that does not exist, and an error is reported only during running, it is necessary to provide a display mechanism, to avoid such errors. Pisces introduced him in Kanas in my best idea for a year. net, here is my implementation in LiteMDA, the principle is basically similar, that is, while the entity class is generated by the auxiliary tool, generates a set of Object Class Attribute dictionaries called PropertyEnumerators.

The following example shows two entity classes: User and Profile. Each User contains a Profile attribute.

UserPropertyEnumerator. cs

Using System;
Using System. Collections. Generic;
Using System. Text;

Namespace LiteMDA. Test. Entitys. PropertyEnumerators
{
Public class UserPropertyEnumerator
{
Private string _ Prefix = null;
Private string _ ID = "User. ID ";
Private string _ Name = "User. Name ";

Public string ID
{
Get
{
Return (_ Prefix! = Null & _ Prefix. Length> 0? String. Format ("{0}. {1}", _ Prefix, _ ID): _ ID );
}
}

Public string Name
{
Get
{
Return (_ Prefix! = Null & _ Prefix. Length> 0? String. Format ("{0}. {1}", _ Prefix, _ Name): _ Name );
}
}

Public ProfilePropertyEnumerator Profile;

Public UserPropertyEnumerator ()
{
This. Profile = new ProfilePropertyEnumerator ("User ");
}

Public UserPropertyEnumerator (string prefix)
{
_ Prefix = prefix;
This. Profile = new ProfilePropertyEnumerator (string. Format ("{0}. {1}", _ Prefix, "User "));
}
}
}

ProfilePropertyEnumerator. cs

Using System;
Using System. Collections. Generic;
Using System. Text;

Namespace LiteMDA. Test. Entitys. PropertyEnumerators
{
Public class ProfilePropertyEnumerator
{
Private string _ Prefix = null;
Private string _ ID = "Profile. ID ";
Private string _ LiveCity = "Profile. LiveCity ";

Public string ID
{
Get
{
Return (_ Prefix! = Null & _ Prefix. Length> 0? String. Format ("{0}. {1}", _ Prefix, _ ID): _ ID );
}
}

Public string LiveCity
{
Get
{
Return (_ Prefix! = Null & _ Prefix. Length> 0? String. Format ("{0}. {1}", _ Prefix, _ LiveCity): _ LiveCity );
}
}

Public ProfilePropertyEnumerator ()
{
}

Public ProfilePropertyEnumerator (string prefix)
{
_ Prefix = prefix;
}

}
}

Entity. cs

Using System;
Using System. Collections. Generic;
Using System. Text;

Namespace LiteMDA. Test. Entitys. PropertyEnumerators
{
Public class Entity
{
Public static PropertyEnumerators. UserPropertyEnumerator User = new LiteMDA. Test. Entitys. PropertyEnumerators. UserPropertyEnumerator ();
Public static PropertyEnumerators. ProfilePropertyEnumerator Profile = new LiteMDA. Test. Entitys. PropertyEnumerators. ProfilePropertyEnumerator ();
}
}

With the above definition, I can add a query Condition Clause as follows:

Condition. Add (Entity. User. Name, OP. Equals, "teddy"). And (Entity. User. Profile. LiveCity, OP. Equals, "shanghai ")

This avoids errors that may not be detected during compilation due to the aforementioned "Hand errors.

// End the article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.