RIA DomainService Query with parameters LightSwitch - ria

I am trying to use RIA services in LightSwitch but I get an error when the query in the DomainService has a parameter because the query is not imported into LightSwitch.
All the other queries are fine.
The error I get when attaching the data source in the Wizard window is
The parameter 'ID' in query 'AllRecordsbyId' is not a nullable type.
This query will not be imported.

make the parameter nullable:
public IQueryable<CategoryTree> GetAllCategoryTree(int? AllRecordsbyId)
{
}

Related

How to provide OData service via the SAP Cloud SDK for an entity with a DateTime in its key?

We are currently struggling with providing an OData service for an entity, which has as part of its key a property of type DateTime. This key property is not part of the key map in the OData request given by the SAP Cloud Provisioning SDK. This seems to be due to a bug in the parsing of the request in the method com.sap.cloud.sdk.service.prov.v2.data.provider.CXSDataProvider.getKeys(List):
if (type.toString().equals("Edm.Date")) {
Date value = type.valueOfString(keyPredicate.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(), Date.class);
keys.put(property.getName(), value);
}
Since there is no Edm.Date type in the OData standard, my guess is that instead the following would have been correct:
if (type.toString().startsWith("Edm.Date")) {
[s. above]
}
Is this correct or are we doing something wrong here? In addition there is a TODO marker on the method itself pointing out that only a subset of EDM types is currently supported as a key. Are there any plans to fix this TODO?
As muchumanoj commented, the issue should be resolved in version 1.29.5 of <groupId>com.sap.cloud.servicesdk.prov</groupId><artifactId>odatav2-prov</artifactId>. Thanks for reporting it.

Use SQL Server view in NEW Azure App Service

I am new to Azure App Service.
I've created a view in Azure database to get data across several tables. Now I want to use the data from this view in my Cordova App using the Azure Mobile Service (MobileService.GetTable...). I found several articles in the web that describe how to do that in Classic Azure Portal. But I need a solution for the NEW Azure App Service with Node.js Backend.
What is the syntax to return data from a view as an Azure table?
var table = module.exports = require('azure-mobile-apps').table();
table.read(function (context) {
// *** Need code to return data from sql view ***
//return context.execute();
});
And it would be great to use a parameter to filter data in the view before returning.
Thanks,
Uwe
You are pretty much right there. You need to just create a table controller to access the view. Ensure you have the system columns defined (version, updatedAt, createdAt, deleted and id). Also, ensure the right thing happens when you update the view (e.g. with an INSERT, UPDATE, DELETE) as that will tell you what needs to be done with the controller (for example, if you can't insert/update/delete, then make it read-only).
Reference blog post for you: https://shellmonger.com/2016/04/15/30-days-of-zumo-v2-azure-mobile-apps-day-8-table-controller-basics/
Things can be so easy sometimes ;-)
All I need to do is to write the following lines to my table controller:
var table = require('azure-mobile-apps').table();
table.databaseTableName = 'ViewName';
module.exports = table;
Thanks for your help!
Had a similar issue but fixed it now, am using a .Net backend thou.
1. Log into azure portal and select the database you want to create the view in Then select the query Editor in the left pane.
2. Use the sql to create the query.
3.Create a table in the asp.net backend that matches your fields in your view.
4.Go to your asp.net backend and create a custom Api and write the following codes:
public class HelloCustomController : ApiController
{
MobileServiceContext context;
public HelloCustomController()
{
context = new MobileServiceContext();
}
[HttpGet]
public async Task<List<vwUser>> Get()
{
try
{
var users = context.Database.SqlQuery<vwUser>("Select * from
dbo.vwUser);
return await users.ToListAsync();
}
catch(Exception ex)
{
return new List<vwUser>()
{
new vwUser
{
UserName=ex.Message
}
};
}
}
4.You edit my codes to select from your view.
5. Create a similar class in your mobile app that matches what u created in your backend.
5. You can then access your view by calling it in your mobile app with the following codes:
var users= await client.InvokeApiAsync<vwUser>("HelloCustom",HttpMethod.Get,null);
Thanks Guys. This is my fisrt answer to this beautiful community that carried me from day 1 of programming till now that am a bit conversant.

How to use Custom Routes with Auto Query

Using the first example in the ServiceStack Auto Query documentation in a project structured similar to the EmailContacts sample project (i.e. separate projects for the ServiceModel and ServiceInterface), how would one register the custom route "/movies" defined by the Route attribute?
[Route("/movies")]
public class FindMovies : QueryBase<Movie>
{
public string[] Ratings { get; set; }
}
Normally, custom routes such as these can be register by passing the ServiceInterface assembly when instantiating AppHostBase:
public AppHost() : base("Email Contact Services", typeof(ContactsServices).Assembly) {}
However, the FindMovies request DTO does not have an associated service and therefore won't be included. No routes are registered.
If I pass typeof(FindMovies).Assembly instead of or in addition to typeof(ContactsServices).Assembly, then the pre-defined route will be registered (i.e. shows up in the metadata, postman, etc.) but the custom route is still not registered (i.e. does not show up in the metadata, postman, etc.).
What is the best way to register the custom route using attributes when there is no service and the ServiceModel and ServiceInterface are in separate projects?
These issues should be resolved in v4.0.24+ that's now available on MyGet.
There's a new AutoQueryFeature.LoadFromAssemblies property to specify an additional list of assemblies to scan for IQuery Request DTO's. This automatically looks in the assemblies where your other Request DTO's are defined so in most cases nothing needs to be done as it will automatically be able to find your query services.
The routes for Query DTO's should now appear on the metadata pages as well as Swagger and Postman metadata API's.

Call to DBContext throws exception (code first, create DB)

I wanted to try EF5 as described here: http://msdn.microsoft.com/en-us/data/jj193542
But as soon as
using (var db = new BloggingContext())
is reached an System.InvalidOperationException is thrown with additional details saying that "The type 'ConsoleApplication1.Program+Blog' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject."
No database is created. I'm using VS 2012 Express for Windows Desktop and SQL Server 2012. The database explorer can connect to the local SQLExpress instance without problems.
Any ideas?
Cheers, mttmjapj
Okay, found the culprit. I unconsciously put the source for Blog and Post into the program class. Which obviously is nested and therefore can't work.

How do I use OData with RIA services

When using RIA services, how do I specify I want to use OData instead of a proprietary format?
I'm new with Odata but currently works on RIA and I found the article from Brad Abrams blog at
http://blogs.msdn.com/brada/archive/2010/03/16/silverlight-4-ria-services-ready-for-business-exposing-odata-services.aspx
After finished prepare everything such a service, you can specify to use OData by calling URL to the DomainService like
"http://localhost:7777/Sample-App-GreatDomainService.svc/OData/YourObject"
Which,
Sample-App-GreatDomainService.svc = Your domainservice namespace(Mine is Sample.App.GreatDomainService) and followed by .svc (see that '.' replaced by '-')
/OData/YourObject = Exposed to the typename in your data model as OData (Mine is "YourObject" type)
This will get an Atom Feed data of type "YourObject" in your project.
Hop this help. ^ ^

Resources