I'm using a DbContext provided by a DomainService in my Silverlight 5 (Beta) application. I'm getting warning messages while building the project:
The attribute 'System.ComponentModel.DataAnnotations.MaxLengthAttribute' requires a reference to System.ComponentModel.DataAnnotations in the client project. Skipping generation of attribute. Please add a reference to System.ComponentModel.DataAnnotations to ensure generation of the attribute.
The thing is that, there is no MaxLengthAttribute attribute in System.ComponentModel.DataAnnotations at client side. In consequence, I'm not able to validate any property length before the record has been sent to the server ... Does anybody know a solution?
MaxLengthAttribute is in EntityFramework.dll and I'm almost sure that it cannot be used in Silverlight because it would require Silverlight version of EntityFramework.dll which doesn't exist.
Try using the StringLengthAttribute instead.
Related
I am migrating an existing ASP.NET Web API 2 project to ASP.NET Core. While migrating I am unable to find this.Request object. Can anyone help me solve out this issue?
This question was asked here, but since ASP.NET Core was still probably in an RC state then, I figured I'd answer here instead of referring to there because there is some stuff that's obsolete or completely gone from the official release.
Assuming your controller class inherits from Controller (or more specifically, ControllerBase) then it does have a this.Request property as you can see here and here. As Pawel noted, you can also access it from the this.HttpContext property.
The request's URL is broken up into several properties on HttpRequest. You can access the URL in a friendlier API by adding using Microsoft.AspNetCore.Http.Extensions; which gets you access to the following extension methods:
GetDisplayUrl()
GetEncodedUrl()
As far as the query string, HttpRequest provides QueryString and Query properties for you to interact with.
Side note: I just created an app from scratch targeting ASP.NET Core on .NET Core for the first time on this laptop, and it took a while for the Intellisense to work for the Request property, so I'm wondering if that could have been your issue.
You need to override your class like this to get this.Request
public partial class _Default : System.Web.UI.Page
I have a Solution with different Projects:
A Silverlight Class Library:
- In this I have a "Link" to the CS File with Attribute wich is used on a DTO
- In this Class there is also a modified Datagrid wich uses the Attribute
A RIA Class Library:
- It has a Link to a web project, and loads my DTO class
- It also has a Reference to the class Library defined before!
A Silverlight Project:
- This is my runtime and loads dynamicly the RIA Project.
Now to the Problem:
The DTO in the RIA Project does not have the Attribute defined on the real DTO! When I move the Attribute to the RIA-Class-Library, it works, but this is not possible, because then I have no access to the attribute from my normal Class Library!
when I did this bevore, using a normal RIA-Project instead of RIA-ClasLibrary, there it worked. It did find the types from the Referenced DLLs.
But now I need the other aproach.
Anyone can help?
Ah, the error code is: The attribute '...' is not visible in the client project '...'
I got it now! Seams like i referenced two Versions of Microsoft.Iteractivity, and this broke Ria from finding the Attributes
I am working on a Silverlight applicaiton. It uses WCF services to pass EF 4 Self Tracking Entities back and forth from client to server.
Read methods are working fine to serve the Trackable entity collections to the Silverlight client from the WCF services. Even basic updates are working correctly. I can modify a property of "OfficeEntity", and pass it as a parameter to a WCF update method.
The issue we are having is when we update one of the Entity's collections, we get the below deserialization error. For example, if "OfficeEntity" has a navigation property "Locations" that is a collection of "LocationEntity", and we add a new "Location" to the "Locations" property and save it, we get the deserialization exception.
officeEntity.Locations.Add(new Location() {LocationName = "Test 1"});
client.SaveAsync(officeEntity);
Exception Details:
The formatter threw an exception while trying to deserialize the message:
There was an error while trying to deserialize parameter :OfficeEntity. The InnerException >message was
'There was an error deserializing the object of type Entities.OfficeEntity.
End element 'ObjectsAddedToCollectionProperties' from namespace >'http://schemas.datacontract.org/2004/07/Entities' expected.
Found element 'b:AddedObjectsForProperty' from namespace >'http://schemas.datacontract.org/2004/07/Entities'.'
It appears the problem is with deserializing the change tracking properties. Any ideas on what causes this or where I can fix it?
Thanks,
Jason
Self tracking entities have issues with tracking if the actual generated entities aren't used in the client - I blogged about it here.
Not sure if this is at the root of your serialization issues but will definitely have an impact on you being able to use self-tracking entities
I'm building a silverlight LOB application which uses both RIA services and a vanilla .ASMX service..
The data is wired up using entity framework..
I have 1 entity which i recently added a 1 to many relationship to a collection of a new type of object..
Using RIA services i can get to that in my silverlight application fine by saying:
instanceOfEntity.NewEntities
However in the vanilla service which is using the exact same object context class even after updating, deleting and recreating the service reference in the silverlight application.. the property is still not being exposed..
Someone Plleeaeeeeease tell my how i can get this dang thing to show up via this service!
Thanks
Daniel
Ended up switching to a WCF service instead..
Seems to work fine,
Not sure if this is a limitation in vanilla ASMX services?
I was using a simple WCF service with silverlight but I wanted to validate data with annotations and I didn't want to write a whole new layer in silverlight project. So I decided to switch to using a DomainService, created through generating code in the silverlight project.
Now comes the trouble. I have a parent class and about 10 derived classes. Through WCF, I was able to just use the base class. Now I am trying to use a DomainService with the base class decorated with the KnownType attribute. The problem is now those attributes get replicated in silverlight client and a compilation error is thrown. Anybody know how to use DomainService with inheritance? I want to deliver only the information from the base class.
I don't completely follow what your problem is, but this is a great tutorial on how to use Domain Services in Silverlight, and the example includes an abstract base class for all entities, similar to what I think you're doing.