views:

60

answers:

2

I am working on custom data provider using ADO .NET Entity Framework.

In the CreateMetaData function, I need to add primitive and complex properties in the ResourceType.

I believe Enum should be added as the complex data type.

If yes, how can I add this? Any pointer would be a great help.

Thanks,

Ram

A: 

An enum can be initialized as following:

public enum MyEnum
{
    FirstEntry,
    SecondEntry,
    ThirdEntry
}

You can access it using MyEnum.FirstEntry.

The enum can be added to a class as a property, for example:

public MyEnum NumberOfEntry { get; set; }

I hope this answers your question.

Peter van Kekem
@Peter van Kekem : The Enum is already define, I need to expose it in CreateMetadata function.
Ram
I don't see why you cannot just assign the enum in the function... maybe you should add some more information around? For example, the createmetadata function you have until now, how you want to assign the ResourceType, etc.
Peter van Kekem
Yes, that's correct, But I feel I need to add the enum as complex type and I do not know how to add it.
Ram
Add the enum to what?
Peter van Kekem
Add enum to ResourceType as a ComplexProperty.
Ram
What type or class is the ResourceType?
Peter van Kekem
Resource type is a class in which I want to add an Enum.
Ram
I've added an example in my answer. Hope this will help you out.
Peter van Kekem
EF4 does not have support for Enum :(
Ram
Then try to add it as an int by casting it to int.
Peter van Kekem
A: 

As mentioned here Enums are not supported in Entity Framework 4. But it can be achieved using POCO classes.

Ram