Open RIA Services User Support POCO entity using Enum  Viewed 44880 time(s), 5 post(s)., 5/12/2014 11:42:04 AM - by muiscatron

muiscatron
muiscatron 5/12/2014 11:42:04 AM

What is the official guidance for using properties of custom Enum types in my entities? I have seen some advice that says to put them in a shared code file. However, I have seen other advice that says that the code generation should create them on the client (at least in part).
As it stands, the code generation seems to ignore every enum in my class.

thanks

This content has not been rated yet. 
60 Reputation 5 Total posts
1
ColinBlair
ColinBlair 5/12/2014 3:00:19 PM

Enum types are working for me, they are generated by the code generation and not put in a shared code file.  Can you paste in an example of your code?

This content has not been rated yet. 
1539 Reputation 130 Total posts
2
muiscatron
muiscatron 5/12/2014 7:02:07 PM

Hi,

I have reproduced the problem in a sample application which I had been using as my guide:

Only 2 entities are present, Task and TimeEntry.

Task

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using OpenRiaServices.DomainServices.Server;
 
namespace TaskMaster.Entities
{
    [RoundtripOriginal]
    public class Task
    {
        public Task()
        {
            TimeEntries = new List<TimeEntry>();
        }
        [Key]
        public int TaskId { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public DateTime? StartDate { get; set; }
        public DateTime? EndDate { get; set; }
 
        [Include]
        [Association("Task_TimeEntries", "TaskId", "TimeEntryId")]
        public List<TimeEntry> TimeEntries { get; set; }
 
        public enum TaskTypes
        {
            Standard = 1,
            Advanced = 2
        }
 
        public TaskTypes TaskType { get; set; }
 
    }
}
<div><br /> TimeEntry<br /> <br />
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using OpenRiaServices.DomainServices.Server;
 
namespace TaskMaster.Entities
{
 
 
    public class TimeEntry
    {
        [Key]
        public int TimeEntryId { get; set; }
        public string Description { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
 
        [Association("Task_TimeEntries", "TaskId", "TaskId", IsForeignKey = true)]
        public Task Task { get; set; }
 
        [ForeignKey("Task")]
        public int TaskId { get; set; }
 
        public enum TimeEntryTypes
        {
            Automatic = 1,
            Manual = 2
        }
 
        public TimeEntryTypes TimeEntryType { get; set; }
    }
}


The domainservice includes methods that return both types (part of class shown below):

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRiaServices.DomainServices.Hosting;
using OpenRiaServices.DomainServices.Server;
using TaskMaster.Entities;
using TaskMaster.Data;
 
namespace EFCodeFirstPOCOServices.Web
{
    [EnableClientAccess()]
    public class TasksDomainService : DomainService
    {
        readonly TaskMasterDataAccess _context = new TaskMasterDataAccess();
        public IQueryable<Task> GetTasks()
        {
 
            return _context.Tasks.Include("TimeEntries");
 
        }
 
//..............................................................................       
 
        public IQueryable<TimeEntry> GetTimeEntries()
        {
            return _context.TimeEntries;
        }
    }
}

The resulting client generated code omits the properties for TimeEntryType and TaskType. 

I guess that there must be something basic wrong here! I just could not find any examples which include what I wanted.
Let me know if you need any more details.

thanks again


</div>

This content has not been rated yet. 
60 Reputation 5 Total posts
3
ColinBlair
ColinBlair 5/12/2014 8:14:46 PM

Move the enum outside of the class definition. It can be in the same file, but not inside the class itself.

This content has not been rated yet. 
1539 Reputation 130 Total posts
4
muiscatron
muiscatron 5/13/2014 10:00:24 AM

Many thanks, this worked for me.

This content has not been rated yet. 
60 Reputation 5 Total posts
5