Page 1 of 1

How to get access to NOT NULL/Maxlength generated properties

Posted: Mon 11 Oct 2010 10:06
by afva
Hello,

(Devart dotConnect for Oracle 6.0.10.0; Devart EntityDeveloper 3.0.10.0)

I want to validate my objects and create error-messages.
For every generated class I write my own partial methods like this:
public partial class classXX: IDataErrorInfo
{
...
partial void OnINFOChanging(string value)
{
if (string.IsNullOrEmpty(value)) ...
if (value.Length > ....)
}

This is a lot of typing, becaue most the fields have these same checks (NOT NULL and stringlength).
When entityDeveloper creates the entities he sees these values. How can I get access to these values/attributes/properties ?



[/code]

Posted: Mon 11 Oct 2010 11:41
by AndreyR
You can use code like the following:

Code: Select all

      MetadataWorkspace mw = context.MetadataWorkspace;
      var entity = mw.GetItems(DataSpace.CSpace).Where(it => it.Name == "").Single();
      foreach (EdmProperty property in entity.Members) {
        foreach (var facet in property.TypeUsage.Facets) {
          if (facet.Name == "Nullable") {
            //The property is nullable
          }
          else if (facet.Name == "MaxLength") {
            int maxLength = (int)facet.Value;
          }
        }
      }      

Posted: Mon 11 Oct 2010 12:41
by afva
Hello Anrey,
Thanks for your answer.

I cannot find the "context.MetadataWorkspace"
I used: using System.Data.Metadata.Edm;

Posted: Mon 11 Oct 2010 13:08
by AndreyR
Have you added the System.Data.Entity assembly into your project's References?

Posted: Mon 11 Oct 2010 13:55
by afva
yes, I did

Posted: Mon 11 Oct 2010 15:37
by AndreyR
Could you please send me (support * devart * com, subject "EF: MetadataWorkspace") a small test project illustrating your scenario?
Maybe I will able to help you in a more effective way.

Posted: Wed 20 Oct 2010 08:58
by afva
Hello AndreyR,

I just send you a rapport

Posted: Thu 28 Oct 2010 12:00
by AndreyR
We have replied to your e-mail.