views:

649

answers:

1

I have an entity with fields that are typed int

and i want to exposed those fields as properties which get and recieve enum type values for working strongly typed.

so i've created a new partial class for the entity and added the two properties.

when i try to create a new instance of the TestEntity and add it to the context , and call save changes i get the following exception:

An error occurred while processing this request. at System.Data.Services.Client.DataServiceContext.SaveAsyncResult.HandleBatchResponse() at System.Data.Services.Client.DataServiceContext.SaveAsyncResult.EndRequest() at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options) at System.Data.Services.Client.DataServiceContext.SaveChanges()

the inner exception is:

System.InvalidOperationException: The type 'enum1' has no settable properties. at System.Data.Services.Client.ClientType..ctor(Type type, String typeName, Boolean skipSettableCheck) at System.Data.Services.Client.ClientType.Create(Type type, Boolean expectModelType) at System.Data.Services.Client.DataServiceContext.WriteContentProperties(XmlWriter writer, ClientType type, Object resource) at System.Data.Services.Client.DataServiceContext.CreateRequestData(ResourceBox box, Boolean newline) at System.Data.Services.Client.DataServiceContext.SaveAsyncResult.CreateChangeData(Int32 index, Boolean newline) at System.Data.Services.Client.DataServiceContext.SaveAsyncResult.BeginNextChange(Boolean replaceOnUpdate)

so i figured it tries to reflect the enum properties as classes properties. how can i make the context ignore those properties when it tries to reflect on them.

i am using VS 2008 team suite sp1 , SQL Server 2008 , .Net 3.5 Sp1.

Help.

the partial class code:

public partial class TestEntity
{     
    public enum1 Field1
    {
        get
        {
            return (enum1)field1;
        }
        set
        {
            field1 = (Int16)value;
        }
    }

    public enum2 Field2
    {
        get
        {
            return (enum2)field2;
        }
        set
        {
            field2 = (Int16)value;
        }
    }   
}
+1  A: 

I don't think that you can. In ADO.Net Data Services, you can't have enums on your proxy objects that get sent up to the server. Try changing your object around to use an int (or short) instead.

Peter Oehlert