lightswitch html client failed to convert circular structure to json - json

Im trying to insert new data into the DB when a user scans a barcode into a field. When I hit save on the screen it says fail to convert circular structure to json.
var report = myapp.activeDataWorkspace.BlanccoData.BMCReports.addNew();
report.c_Date = Date.now();
report.IsScannedReport = true;
if (contentItem.screen.ScanSSN == true) {
report.SSN = contentItem.value;
}
var system = myapp.activeDataWorkspace.BlanccoData.BMCSystemInfo.addNew();
// system.Report = report;
system.Barcode = contentItem.screen.Barcode;
I think the commented line is throwing the exception but I need to reference it.
thanks

Have you considered that you may have a circular relationship in your database? That is reflected in your DataSource?

Related

Is SchemaCrawler broken when using its API?

I am refering the doc in http://sualeh.github.io/SchemaCrawler/how-to.html#api
But I never get what I want. The tables returned is always empty.
final Connection connection = ... // Get a MYSQL connection;
final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
options.setSchemaInfoLevel(SchemaInfoLevelBuilder.maximum());
options.setTableInclusionRule(new IncludeAll());
options.setTableNamePattern("*");
final Catalog catalog = SchemaCrawlerUtility.getCatalog(connection, options);
for (final Schema schema: catalog.getSchemas())
{
Collection<Table> tables = catalog.getTables(schema);
//
// The size of tables is always 0
//
System.out.println(tables);
}
You should not set the table name pattern, so please remove the following line:
options.setTableNamePattern("*");
Sualeh Fatehi, SchemaCrawler

Username in WebTokenRequestResult is empty

in a Windows 10 UWP I try use WebAuthenticationCoreManager.RequestTokenAsync to get the result from a login with a Microsoft account.
I get a WebTokenRequestResult with Success. ResponseData[0] contains a WebAccount with an ID - but the UserName is empty.
The scope of the call is wl.basic - so I should get a lot of information...
I'm not sure how to retrieve extra information - and for the current test the Username would be OK.
I checked out the universal samples - and there I found a snippet which tries to do what I'm trying - an output of webTokenRequestResult.ResponseData[0].WebAccount.UserName.
By the way - the example output is also empty.
Is this a bug - or what do I (and the MS in the samples) have to do to get the users profile data (or at least the Username)?
According to the documentation (https://learn.microsoft.com/en-us/windows/uwp/security/web-account-manager), you have to make a specific REST API call to retrieve it:
var restApi = new Uri(#"https://apis.live.net/v5.0/me?access_token=" + result.ResponseData[0].Token);
using (var client = new HttpClient())
{
var infoResult = await client.GetAsync(restApi);
string content = await infoResult.Content.ReadAsStringAsync();
var jsonObject = JsonObject.Parse(content);
string id = jsonObject["id"].GetString();
string name = jsonObject["name"].GetString();
}
As to why the WebAccount property doesn't get set... shrugs
And FYI, the "id" returned here is entirely different from the WebAccount.Id property returned with the authentication request.

JSON validator validates the JSON but my left hand tags are not appearing

i am developing an iOS app and this app fetches data using JSON from mysql database. i have configured the json properly so far. right hand $outputs are ok and json validator validated the json formatting is completely ok. but my left hand tags are not appearing some how. here i m providing the code what i did. For this app publishing is on hold for long time.
//fetch data from current month table
$q = mysql_query("SELECT * FROM $monthyear where news_date = '$date'");
if (!$q) {
die('Invalid query executed: ' . mysql_error());
}
while($e=mysql_fetch_row($q)){
$output[]=$e;
$responce[$e]['news_id'] = $output['news_id'];
$responce[$e]['news_title'] = $output['news_title'];
$responce[$e]['news_reporter'] = $output['news_reporter'];
$responce[$e]['news_details'] = $output['news_details'];
$responce[$e]['photo'] = $output['photo'];
$responce[$e]['path'] = 'admin/'.str_replace('\\','',$output['path']);
$responce[$e]['menu_id'] = $output['menu_id'];
$responce[$e]['menu_type'] = $output['menu_type'];
$responce[$e]['news_publish_status'] = $output['news_publish_status'];
$responce[$e]['news_order'] = $output['news_order'];
$responce[$e]['news_date'] = $output['news_date'];
$responce[$e]['news_time'] = $output['news_time'];
$responce[$e]['added_by'] = $output['added_by'];
$responce[$e]['directory'] = $output['directory'];
$responce[$e]['read_number'] = $output['read_number'];
$responce[$e]['comment_number'] = $output['comment_number'];
$responce[$e]['news_comment_table_name'] = $output['news_comment_table_name'];
}
echo(json_encode($output));
I am not getting any way to show left hand tags though it exists in the script. can any one help me on this by guiding or giving an example from existing source code after modifications. TIA
Ishtiaque
You are using $e which is an array as an array key in $response[$e], and this is not allowed in PHP:
Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.
I think you want to use the ID as a key.

how to convert type 'system.linq.iqueryable<byte[]>' to 'byte[]'

In Linq to SQL asp.net, I want to fetch a specific image from database and display on an aspx page. I declared returned type as "var" on the code. So after fetching the image, it assigns image to var type.
Here is the code:
var db = from c in context.Images
where c.imageId == iID
select c.imageData;
return new MemoryStream((byte[])db); ---->> this line of code gives error
It gives this compile error: Cannot convert type 'system.linq.iqueryable' to 'byte[]'.
How can I convert 'system.linq.iqueryable type to byte[] ?
Your problem is that you're selecting a collection of byte[] rather than a single byte[].
Depending on the behavior you want for your application, you can use Single, SingleOrDefault, First, or FirstOrDeault:
var image = context.Images.FirstOrDefault(i => i.imageId == ID);
if(image == null)
{
// Handle the case where no image was found.
//
// First or Single would throw Exceptions in this case
// if that's what you want.
}
else
{
return new MemoryStream(image.imageData);
}
try below line this work for me
var db = (context.Images.FirstOrDefault(i => i.imageId == ID).ImageData

Getting identity column value using entity framework 4.1

I'm using entity framework 4.1 (VS 2010, SQL Server 2012) for inserting data into a database.
First I create an instance of an object, fill the properties with values and call AddObject(), like this:
VideoData videodata = new VideoData();
videodata.StartCaptureTime = startCaptureTime;
videodata.EndCaptureTime = endCaptureTime;
videodata.CameraID = CameraID;
using (var context = new PercEntities())
{
if (context.VideoDatas.Where(c => c.VideoID == videoID).Count() == 0)
{
var videoData = new VideoData
{
StartCaptureTime = startCaptureTime,
EndCaptureTime = endCaptureTime,
CameraID = CameraID,
};
context.VideoDatas.AddObject(videoData);
context.SaveChanges();
}
}
The thing is, that the table in the database has an identity column:
VideoID int IDENTITY(1,1)
and I need to get the value inserted by the identity function in order to fill additional objects, that have the VideoID as a foreign key. for example:
FrameData frameData = new FrameData();
frameData.VideoID = videodata.VideoID;
frameData.Path = path;
The only thing I could think of was to query for the max identity right after AddObject(videoData), but I'm afraid of race conditions.
I'm new to Entity Framework, so I'd be happy for any guidance on this.
If you have other objects which require VideoID as FK you just need to correctly configure your navigation properties between VideoData and those other types and EF will handle it for you.
Call to AddObject does not insert your data to database and because of that you cannot get the identity value after this call. Only call to SaveChanges will push all your changes to database and during this call EF will handle referential integrity internally (but only if you have your model correctly configured with relations).
After calling SaveChanges your VideoID should be populated automatically if you have everything correctly configured.