ADO.NET Data Services support

Posts   
1  /  2  /  3
 
    
Posts: 134
Joined: 10-Jan-2007
# Posted on: 06-Mar-2009 00:15:24   

I think the fix is to add an IgnorePropertiesAttribute for the parent classes (BusinessEntity) to the LinqMetatData class (to survive regen, create another partial class).

Brian

tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 06-Mar-2009 04:32:43   

I added "Contact" (ContactEntity is the supertype) like so:


    [IgnoreProperties("Contact", "CustomPropertiesOfType", "FieldsCustomPropertiesOfType", "Validator", "AuthorizerToUse", "AuditorToUse", "Fields", "Transaction", "ConcurrencyPredicateFactoryToUse", "TypeDefaultValueProviderToUse", "PrimaryKeyFields", "LLBLGenProEntityTypeValue", "LLBLGenProEntityName", "ActiveContext", "IsDirty", "IsNew", "ObjectID", "ParticipatesInTransaction", "IsDeserializing")]
    [DataServiceKey("ContactId")]
    /// <summary>partial class for adding ADO.NET specific attributes to the generated entity class</summary>
    partial class BusinessEntity
    {       
    }

but get the same error message. Is this what you meant?

Posts: 134
Joined: 10-Jan-2007
# Posted on: 06-Mar-2009 15:00:33   

Add it to the LinqMetaData class [IgnoreProperties("Contact")] public partial class LinqMetaData { ... }

tomahawk
User
Posts: 169
Joined: 02-Mar-2005
# Posted on: 07-Mar-2009 02:23:01   

After doing this and attempting to access the dataservice, I get the following error:


The server encountered an error processing the request. The exception message is 'Ambiguous match found.'. See server logs for more details. The exception stack trace is:

at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) at System.Type.GetProperty(String name, BindingFlags bindingAttr) at System.Data.Services.IgnorePropertiesAttribute.GetProperties(Type type, Boolean inherit, BindingFlags bindingFlags) at System.Data.Services.Providers.ReflectionServiceProvider.BuildTypeProperties(ResourceType parentResourceType, IDictionary`2 knownTypes, Queue`1 unvisitedTypes, IEnumerable`1 entitySets) at System.Data.Services.Providers.ReflectionServiceProvider.PopulateMetadataForTypes(IDictionary`2 knownTypes, Queue`1 unvisitedTypes, IEnumerable`1 entitySets) at System.Data.Services.Providers.ReflectionServiceProvider.PopulateMetadata(IDictionary`2 knownTypes, IDictionary`2 entitySets) at System.Data.Services.Providers.BaseServiceProvider.PopulateMetadata() at System.Data.Services.DataService`1.CreateProvider(Type dataServiceType, Object dataSourceInstance, DataServiceConfiguration& configuration) at System.Data.Services.DataService`1.EnsureProviderAndConfigForRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Is this because I have several subtypes of 'Contact', or that the property 'Contact' appears in many classes?

vassos
User
Posts: 32
Joined: 24-Jun-2008
# Posted on: 09-Mar-2009 13:50:19   

tolo wrote:

I will try to modify the templates to handle the inheritance problems, it doesn't look difficult.

You'll have one beer from me if you do that simple_smile . Good luck. I'm sure it's not a rocket science but when I had to deal with this I gave it up.

tolo
User
Posts: 15
Joined: 27-Mar-2005
# Posted on: 19-Mar-2009 20:56:53   

vassos wrote:

tolo wrote:

I will try to modify the templates to handle the inheritance problems, it doesn't look difficult.

You'll have one beer from me if you do that simple_smile . Good luck. I'm sure it's not a rocket science but when I had to deal with this I gave it up.

I am really sorry but I had to stop my tests with this template and data services because I'm really busy with another project flushed

I added to the template IgnoreProperties to LinqMetaData class to "fix" the inheritance problem. Unfortunately I don't have idea how to avoid the last ','

I need to change the template to add [IgnoreProperties("CustomPropertiesOfType", "FieldsCustomPropertiesOfType", "Validator", "AuthorizerToUse", "AuditorToUse", "Fields", "Transaction", "ConcurrencyPredicateFactoryToUse", "TypeDefaultValueProviderToUse", "PrimaryKeyFields", "LLBLGenProEntityTypeValue", "LLBLGenProEntityName", "ActiveContext", "IsDirty", "IsNew", "ObjectID", "ParticipatesInTransaction", "IsDeserializing")] to each entity class. Well, not each one, at last not the inherited ones.

I need to change the template to add [DataServiceKey("ID")] to each entity class where ID is the primary key

My proyect can compile and run with this changes, but I didn't had time to test it a lot, sorry confused

I'm not sure if data services right now are useful for my future silverlight project, may be the new Microsoft RIA Services are better.

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 05-Nov-2009 15:28:39   

tomahawk wrote:

I would be very interested to know what the inheritance fixes are, as I am attempting to build an ADO Data Service web portal. I get the following response from the service:


The server encountered an error processing the request. The exception message is 'Property 'Contact' and 'Business' are IQueryable of types 'CL.DAL.EntityClasses.ContactEntity' and 'CL.DAL.EntityClasses.BusinessEntity' and type 'CL.DAL.EntityClasses.ContactEntity' is an ancestor for type 'CL.DAL.EntityClasses.BusinessEntity'. Please make sure that there is only one IQueryable property for each type hierarchy.'. See server logs for more details.

Has anybody ever found the answer to this as I get the same type of error message?

Thanks, Patrick

PS: I'm happy to post a quick sample project for testing.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 06-Nov-2009 11:09:30   

No, nor do we know the answer, as it seems to be related to ado.net dataservices but we honestly don't know.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 06-Nov-2009 17:47:17   

Finally took some time to look at this, here is what I changed:

  1. The IgnoreProperties on sub types need changed to not include some of the parent properties.
  2. Output correct DataServiceKey for subtypes
  3. Added an Ignore foreach SuperType

Having done all this, it "sort of" works. The service creates bad xml for the metadata when there is inheritance: http://local.host/yourservice.svc/$metadata

The issue here is that the DataServiceUtil that generates client libraries uses the metadata. The service itself appears to operate (you can query it). This appears to be a known issue and will not be fixed in 1.5 (see comments) - http://blogs.msdn.com/astoriateam/archive/2009/08/31/ado-net-data-services-v1-5-ctp2-now-available-for-download.aspx

I may try to take a look at this later.

What is the protocol for posting attachment updates? Should I post them to the beginning?

Brian

Attachments
Filename File size Added on Approval
LinqADODSTemplates - NOREFLECT.zip 16,216 06-Nov-2009 17:47.41 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 06-Nov-2009 19:22:02   

Just add them to the post. Many many thanks for the time you spent on this, Brian! smile

Frans Bouma | Lead developer LLBLGen Pro
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 09-Nov-2009 16:19:55   

brianchance wrote:

  1. The IgnoreProperties on sub types need changed to not include some of the parent properties.
  2. Output correct DataServiceKey for subtypes
  3. Added an Ignore foreach SuperType

Hi Brian,

thank you very much for working on it.

When I tried the new templates I still got this error:

The exception message is 'Property with same name 'EntityBaseID' already exists in type 'PW.Spike.ORM.LLBLGen.EntityClasses.ShotEntity'. Please make sure that there is no property with the same name defined in one of the ancestor types.'. See server logs for more details. The exception stack trace is:

What fixed it was to add the PrimaryKey field of the subtypes to the IgnoreProperties attribute on the subtype as the property is already defined in the supertype.

Thanks, Patrick

Posts: 134
Joined: 10-Jan-2007
# Posted on: 09-Nov-2009 16:23:58   

Having never worked with subtypes, can you give me some guidance on how to setup my subtypes to recreate this? I just created 2 subtypes with discriminators, are you adding a different primary key to the subtype?

I can add some code to automatically add the parents key if it is available in the TDL.

Brian

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 10-Nov-2009 01:02:16   

brianchance wrote:

Having never worked with subtypes, can you give me some guidance on how to setup my subtypes to recreate this?

Attached a quick sample solution.

Make a DB called TaraSculpture and run CreateTablesDB.sql on it.

This is the LLBLGen file PW.Spike.ORM.LLBLGen.lpg

Hope it helps, Patrick

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 13-Nov-2009 15:28:54   

I heard MS is going to release a v1.5 version for .NET 3.5 SP1, so not a side-by-side update, but a replacement install for astoria for .net 3.5 sp1. This is the version that's equal to the one in .net 4.0

Not sure what the impact will be, as I have no knowledge of what astoria can do in detail and how it works.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 134
Joined: 10-Jan-2007
# Posted on: 13-Nov-2009 23:12:44   

Patrick - Not sure about this, but I am pretty sure you do not need to map the parents PK field into the sub-type. I believe all super-type fields are available as defined to the sub-type.

Mapping the parent property again causes the sub-type to override the parent property, even though they are the same thing. Take a look at the code generated.

Frans - I will attempt to look at the 1.5 version changes. I have not looked hard but they have supposedly made it "easier" to implement.

Brian

Posts: 134
Joined: 10-Jan-2007
# Posted on: 19-Nov-2009 17:52:31   

I will attempt to look at the 1.5 version changes

Took a look at ADO.NET Data Services 1.5 CTP2 and it looks like this interface is still supported, in fact the IUpdateable is the recommended way for Linq to SQL.

Issues: I did get the heirarchies to work, however you cannot use the super-types as relations on your entities. Basically, if you have the Employee, Manager, BoardMember hierarchy, Employee should be abstract and not used in any relations.

The new "Data Services Layer" in 1.5 is quite a bit more complicated and is targeted at models "based on late-bound data types". I believe this is targeted a the Azure tables model. I think it would be possible to create an LLBLGen specific provider to handle the heirarchies fully, but would be some serious effort, especially without any good documentation.

Brian

pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 03-Dec-2009 11:55:03   

brianchance wrote:

Patrick - Not sure about this, but I am pretty sure you do not need to map the parents PK field into the sub-type. I believe all super-type fields are available as defined to the sub-type.

I didn't do any special mapping. This is how LLBLGen correctly generates the code.

The only change is needed in your template to add the ignore attribute.

Thanks, Patrick

Posts: 134
Joined: 10-Jan-2007
# Posted on: 03-Dec-2009 15:48:03   

Patrick,

Try the attached. I was just creating a sub-type for an entity, I think you are using the target-per-entity heirarchy. The entities are added differently.

Brian

Attachments
Filename File size Added on Approval
LinqADODSTemplates - NOREFLECT.zip 16,240 17-Dec-2009 15:00.05 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 17-Dec-2009 10:25:45   

you might want to know this simple_smile (.NET framework only)

We are very excited to announce that the ADO.NET Data Services Update for .NET 3.5 SP1 is now available online for public download!

This update represents a major step forward for the Data Services team in building an eco-system around the OData protocol and the Data Services framework. This update enables integrating OData into applications and services by adding a rich custom provider model that makes it easier to expose almost any data source as an OData feed. We have also added additional features to the framework (including: data binding, server-driven paging, projection, and more) that make the end to end experience of interacting with a Data Service richer. Keep an eye out for the corresponding update to the Silverlight client library that is coming in the new year. Built-in integration with Microsoft Office Sharepoint means that Sharepoint installations that include this update will automatically start exposing lists and documents as OData feeds that can be consumed using the client library in this update.

This Data Services update can be downloaded from the Microsoft Download Center:

For more information on features included in the update, check out the Astoria team blog: http://blogs.msdn.com/astoriateam/

  • The Astoria Team
Frans Bouma | Lead developer LLBLGen Pro
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 17-Dec-2009 13:23:35   

brianchance wrote:

Patrick, Try the attached. I was just creating a sub-type for an entity, I think you are using the target-per-entity heirarchy. The entities are added differently. Brian

Hi Brian, your post didn't contain any attachment. Thanks, Patrick

Posts: 134
Joined: 10-Jan-2007
# Posted on: 17-Dec-2009 15:01:10   

I have posted them before, I am sure.

Can we get the attachment approved? I added it to the previous post where it says I posted it simple_smile

Frans - I will take a look when the Astoria team posts a clear cut example of the Data Services Provider. For now, the current one should work (sans the inheritance issue).

Brian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 17-Dec-2009 15:27:09   

brianchance wrote:

I have posted them before, I am sure.

Can we get the attachment approved? I added it to the previous post where it says I posted it simple_smile

done. simple_smile

Frans - I will take a look when the Astoria team posts a clear cut example of the Data Services Provider. For now, the current one should work (sans the inheritance issue). Brian

Great! thanks for the work on this simple_smile

Frans Bouma | Lead developer LLBLGen Pro
jjnies
User
Posts: 66
Joined: 07-Nov-2007
# Posted on: 04-Jan-2010 17:27:13   

Hi Brian, great template! Thank you very much for that!

I am having some problems saving related entities and was wondering if you could provide some guidance.


        private void AddNewUser(UserEntity user, string newPassword)
        {
            //add user
            user.Username = "Silverlight";
            user.Password = newPassword;

            if (user.Id.Equals(0))
            {
                ctx.AddToUser(user);
            }
            else
            {
                ctx.UpdateObject(user);
            }

            //add a new appointment to the user
            AppointmentEntity appt = new AppointmentEntity();
            appt.Subject = "Generated From Silverlight application";
            user.Appointment.Add(appt);

            ctx.BeginSaveChanges(SaveChangesOptions.Batch, new AsyncCallback(OnSaveComplete), null);
        }

This code will indeed add a new user to my database, but not an appointment. Just a learning curve I can't seem to grasp with ADO ds.

When I add this code:



ctx.AttachTo("Appointment", user.Appointment);
            ctx.AddLink(user.Appointment, "Appointment", user);

I get errors saying the entity is not being tracked.

Have you or anyone created a sample Silverlight application using these templates? Any help would be greatly appreciated.

Thanks!

-J

Posts: 134
Joined: 10-Jan-2007
# Posted on: 05-Jan-2010 14:50:09   

jjines -

Every object in ado.net needs added to the context, including relations. You need to add the user, appointment and the relationship between the 2 to the context, then SaveChanges.

In 1.5, I think you can use an ObservableCollection<T> and the datacontext somehow to automatically track all changes (I think it is when you fetch over linq, like ToObservableEntityCollection()). It uses INotifyPropertyChanged and ICollectionChanged events to know what is added.

Brian

jjnies
User
Posts: 66
Joined: 07-Nov-2007
# Posted on: 05-Jan-2010 15:41:11   

brianchance wrote:

jjines -

Every object in ado.net needs added to the context, including relations. You need to add the user, appointment and the relationship between the 2 to the context, then SaveChanges.

In 1.5, I think you can use an ObservableCollection<T> and the datacontext somehow to automatically track all changes (I think it is when you fetch over linq, like ToObservableEntityCollection()). It uses INotifyPropertyChanged and ICollectionChanged events to know what is added.

Brian

Thank you Brian!

Do you happen to have an example of how to add a relationship to the context?

1  /  2  /  3