Dynamic Data Entity Framework missing Decimal Column - asp.net

I'm trying to build a Dynamic Data website to act as a simple admin interface to a MySQL database.
This isn't my area of expertise - but it all looks pretty straightforward when following the microsoft website. However for some reason when using the Entity Data Model to the project, the edmx model is created, but doesn't read one of the tables correctly.
In the MySQL database I have a large table containing 9 columns. The first column is the primary key and is an INT. The remaining columns are of type Decimal with a length of 6,2.
The edmx file shows the INT column - but fails to read any of the Decimal columns. If I change these to VARCHAR columns - everything is read perfectly?
The Dynamic Data Field Templates contains a control for decimals and surely the entity framework must be able to recognize columns of DECIMAL type - so I must be doing something wrong - I just can't work out what!
Any help much appreciated!
Cheers
Darren

Ok -I discovered the answer myself!
The issue was due to using unsigned decimal values in the table structure.
Dynamic Data / Entity frame work does not recognise the decimal data type if the column is marked as unsigned. When I changed this, the entity framework was able to read the DB structure correctly!
Hope this helps anyone else who comes across the same issue!
Cheers
Darren

Dynamic Data / Entity frame work does not recognize the decimal data type if the column is marked as unsigned. When I changed this, the entity framework was able to read the DB structure correctly!
I got it with:
Property(x => x.NameColumn).HasColumnName(#"NameColumn").HasColumnType("decimal").IsRequired().HasPrecision(9, 4)

Related

Powerapps - get stuck with UpdateContext

I am trying to build a PowerApp to log setup times of our machines by our fitters.
This is what my app looks like:
There are buttons named "Uhrzeit". Pressing these will write the current date and time into the Date/Time fields. I am using the following code:
UpdateContext({Total8:(Text( Now(); "[$-de-DE]dd/mm/yyyy hh:mm:ss" ))})
The Date/Time field is named Total8.
The code is working well but after saving the form and opening a new record the old data is still available in the fields. By clicking on the button "Zeiten zurücksetzen" I can "delete" the old data.
UpdateContext({Total8:""})
Problem: When I open one of the older records the old data is not available in the form. There is only the value of the last record. In the Common Data Service where my records are saved the values are correct.
As an example, I am saving this record:
When I open a new record, the values of the record 1 are still available. This should not be the case if my app worked properly.
For your Information:
If I enter the date/time without tapping the button, saving the record and opening a new record I don't have the problem. I think the "UpdateContext" code is not the code I should use here.
Can anyone help me solve the problem?
I don't think there's a problem with using the contexts in this way -- but remember that a context is just a variable. It isn't automatically linked to a datasource in any special way - so if you set it equal to Now(), it's going to keep that value until you do something different.
When you view an old record, you need to get the data from CDS and update your contexts to match the CDS data. Does this make sense?
Yeah thats my problem.
I want the variable to be linked to a datasource. Or is it possible to write the date/time into the fields without using a context variable?

icCube parent/child dimension sort error

I have a child/parent hierarchy with columns: AreaName,ParentArea
When I build the cube, I get the error:
The data of the parent/child hierarchy (AreaName) must be sorted (child-id:X,parent-id:Y).
This error is referring to the 2nd row in my csv data source. The first row has a blank value for ParentArea so maybe this is having some impact?
I double checked my source data and the values are sorted by AreaName,ParentArea. I then changed the sort order to ParentArea,AreaName and that seems to work although I don't understand why.
thanks
In icCube you've a view that allows for sorting a parent / child relation as expected by the dimension (doc).
If your data source is a relational database the algorithm for sorting a parent/child relation are described in this stackoverflow post.

Asp.Net C# Entity Framework Distinct messes up Order

I'm working with a ASP.Net MVC4 application using C3 and the Razor engine!
I have a database called builds which contains various columns, like version, creation date.
The database has doubles of Versions, i.e 4.0.230, 4.0.230, 4.0.229, 4.0.229. This is because to tell which version correspond to which environment. like if the Version isX64 etc.
So there is a Version for each environment.
I have a Entity Framework line asking to retrieve the last 10 builds:
var lastVersions = db.Builds.OrderByDescending(b => b.CreationDate).Take(10).Select(b=>b.Version);
so im ordering them by creation date and taking the last 10
it looks like this
4.0.240
4.0.240
4.0.239
4.0.239
4.0.238
etc
then with this line of code:
ViewBag.Versions = lastVersions.Distinct().ToArray();
I would like: [4.0.240, 4.0.239, 4.0.238, 4.0.237, 4.0.236]
but i get: [4.0.236, 4.0.237, 4.0.238, 4.0.239, 4.0.240]
Basically the OrderbyDescending is not working.
Please Help
All help is much appreciated!
thanks!
Without seeing your database, it looks like your OrderByDescending is indeed working, but you actually need to order twice. Your first time, you order by creation date to get the most recent 10 builds, but then after the select, the order is not guaranteed anymore when stuffed into a var. You must sort again by version number. Assuming ViewBag.Versions is a string[], you could do:
Array.Sort(ViewBag.Versions);
or
Array.Reverse(ViewBag.Versions);
if they are in ascending order initially.

Change Field Type from Int to Float

I'm helping a co-worker with a Drupal (6) issue, but I've never used Drupal before. The client wants to store decimal values in a field that was originally defined as an integer. I can't believe that this isn't possible without losing content or without doing a bunch of SQL copying, but I can't find anything that says, "sure, you can update the field type pretty easily, just do...".
Is this possible? So far:
We've altered the the content_type_thing table so that the _value field is now a float data type rather than an int.
We've updated the content_node_field table so the type value for that field is number_float
Now we can change the value from 1840 to 1840.25 without getting a validation error, but the .25 never gets saved. It gets chopped off and we get 18.00 in the database.
Any ideas?
Thanks.
UPDATE
Before anyone asks, I have read this post, but it looks like the recommendation involves a bunch of data migration. I just can't believe that there's not a way to change the data type in place.
This is pretty straight forward my friend. download this module
http://drupal.org/project/formatted_number
When you install it, go to the content type and change that field to use float.
Actually there is a solution but it's not easy and if you don't know exactly what
you're doing it may have side effects
https://drupal.stackexchange.com/questions/79378/changing-a-field-type-from-integer-to-decimal

Giving GUID for data using NDBUnit

I am using NDBUbit to load data from XML file.Right now,I am manually giving GUID for each record(our primary key for all tables is unique-identifier) in the xml file.But,I wonder if there is a better way to do this?
For all test data in XML files for support of NDbUnit where your PK values are of type GUID, take note that all that's required is for the data type to be a GUID -- its doesn't actually have to be a 'random' GUID.
For such test data, so that you can properly reference other PKs in FKs (for example), I always recommend 'deterministic human-created GUIDs' be used in your test data. They both satisfy the req'ment that the value be a GUID and make working with them easier when you are crafting your test data.
As an example, see the following:
<?xml version="1.0" encoding="utf-8" ?>
<UserDS xmlns="http://tempuri.org/UserDS.xsd">
<Role>
<ID>11111111-1111-1111-1111-111111111111</ID>
<Name>Admin</Name>
<Description>Serves as an administrator</Description>
</Role>
<Role>
<ID>22222222-2222-2222-2222-222222222222</ID>
<Name>User</Name>
<Description>User with limited security</Description>
</Role>
<dbo.User>
<ID>22222222-2222-2222-2222-222222222222</ID>
<FirstName>John</FirstName>
<LastName>Williams</LastName>
<Age>30</Age>
<SupervisorID>11111111-1111-1111-1111-111111111111</SupervisorID>
</dbo.User>
<dbo.User>
<ID>11111111-1111-1111-1111-111111111111</ID>
<FirstName>Hammad</FirstName>
<LastName>Awan</LastName>
<Age>29</Age>
</dbo.User>
<UserRole>
<UserID>11111111-1111-1111-1111-111111111111</UserID>
<RoleID>11111111-1111-1111-1111-111111111111</RoleID>
</UserRole>
<UserRole>
<UserID>22222222-2222-2222-2222-222222222222</UserID>
<RoleID>11111111-1111-1111-1111-111111111111</RoleID>
</UserRole>
<UserRole>
<UserID>11111111-1111-1111-1111-111111111111</UserID>
<RoleID>22222222-2222-2222-2222-222222222222</RoleID>
</UserRole>
</UserDS>
In this case, to manage this test data all you need to 'know' about GUIDs is that they are 32chars long in the format 8chars-4chars-4chars-4chars-12chars. There's NOTHING that keeps all the characters from being the SAME if you are crafting your test data 'by hand' like this. This approach eliminates any need to generate "actual GUIDs" for your test data and permits you to easily refer to these by simple repeat-representations of GUIDs as shown in the sample above.
Note that in this kind of a scenario YOU are taking 100% of the responsibility for the 'uniqeness' of the GUIDs that you enter into your test data so this test data can only safely be used in isolation from other GUID-based data rows. This (generally) shouldn't be any issue as the whole point of NDbUnit is to load and manage data such as this in isolation.
If you don't want to edit your test data by hand in an XML file like this, we are close to an alpha-release of a tool called 'NDbUnit DataSet Editor' that provides a GUI for editing test data and also contains a 'Generate and insert GUID' toolbar button for just such situations. However, do note that the GUIDs generated in such a case will be 'real' GUIDs meaning that copy-and-paste would be the only reasonable way to reference one as a FK of another record elsewhere in the DataSet.
Hope this helps.

Resources