How to get access to NOT NULL/Maxlength generated properties

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
afva
Posts: 39
Joined: Thu 13 Aug 2009 21:22

How to get access to NOT NULL/Maxlength generated properties

Post by afva » Mon 11 Oct 2010 10:06

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]

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 11 Oct 2010 11:41

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;
          }
        }
      }      

afva
Posts: 39
Joined: Thu 13 Aug 2009 21:22

Post by afva » Mon 11 Oct 2010 12:41

Hello Anrey,
Thanks for your answer.

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

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 11 Oct 2010 13:08

Have you added the System.Data.Entity assembly into your project's References?

afva
Posts: 39
Joined: Thu 13 Aug 2009 21:22

Post by afva » Mon 11 Oct 2010 13:55

yes, I did

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 11 Oct 2010 15:37

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.

afva
Posts: 39
Joined: Thu 13 Aug 2009 21:22

Post by afva » Wed 20 Oct 2010 08:58

Hello AndreyR,

I just send you a rapport

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 28 Oct 2010 12:00

We have replied to your e-mail.

Post Reply