Why is the master data service from SQL Server 2016 creating a text field as the primary ID? - master-data-services

If I create a new entity from excel, or from the UI and select "Generate code automatically" for the Code attribute, MDS creates an attribute of the type "Free-form - Data Type : Text, Length : 250" !? Why not "Number, Decimals: 0"?

MDS does not give you control over the attribute types for the two default fields 'Name' and 'Code' on any entity. That is unfortunately how it was designed.
In the back-end, MDS actually uses integers as the primary keys for the entities it generates. You can look at how this is done by creating a subscription view in the web-app, and then logging onto the database with SSMS and scripting the view you created. You will see a few more attributes created and used.

Related

Rails 5.1.2 - Single Table Inheritance: No migration is getting generated

I am trying to generate scaffolding for STI implementation. I issue the following.
rails g scaffold user1 type name email
rails g scaffold member company subscription --parent user1
Every thing gets generated file except for the migration file my 'member' model.
When I try to create a member record like this
Member.create(name: "My Name", email: "myname#example.com",
company: 'Example LLC', subscription: 'Monthly Gold' )
I get this error:
ActiveModel::UnknownAttributeError: unknown attribute 'company' for Member. from (irb):1
Any ideas on what is going on?
I use rails 5 and db is postgres
The --parent option assumes that you are already all setup for single table inheritance, i.e. the parent class has a table with a type column (or whatever column you are using for this).
Since the model will be stored in the parent's table, there is no need to create a new table for the subclass, hence no migration
I got this answer similar to this question asked by someone.
To my understanding, you are on the wrong track. In single table inheritance, all the attributes must be present in the parent model table with an additional column name 'type' to indicate the type of inherited model. The column name 'type' can be changed with appropriate settings but ActiveRecord by default looks for 'type' column. You are getting 'UnknownAttributeError' error cause the parent model does not have the following column in its table. You need to write a migration to add the new columns. Hope you understand the concept of STI. For further exploration, I am providing you the link of the official guide. Hope your problem will be solved.
http://edgeguides.rubyonrails.org/association_basics.html#single-table-inheritance

web2py Validation

I would like to know validation is a must, on fields which are not present on the form but are available in the table. Does marking them as NULL in the define_table make them validated only when they are present in the form?
The form validators apply only to forms, so will not affect fields that are not present in the form. I'm not sure what you mean by marking a field as NULL, but if you are referring to Field(..., notnull=True), that executes the SQL NOT NULL statement when the database table is first created (assuming DAL migrations are enabled). That option is enforced by the database itself whenever a record is inserted or updated (via a form or any other method). If a notnull field is left empty, it will result in an operational error from the database.

Entity Framework 4.1 Complex Type reuse in different models

Here is the senario for which I could not find anything useful. Maybe Im the first person thinking of doing it this way:
Approach: Database First
Database: SQL Server 2008 R2
Project : DLL (Data Access)
I have a data access library which encapsulates all the access to database as well as the biz functionality. The database has many tables and all the tables have the following 2 columns:
last_updated_on: smalldatetime
last_updated_by: nvarchar(50)
The project contains several models (or edmx files) which contain only related entities which are mapped to the tables they represent. Since each of the table contain the columns for last_updated_* I created a complex type in one of the models that is as follows:
Complex Type: History
By (string: last_updated_by)
On (DateTime: last_updated_on)
The problem is that it can only be used in the model in which I defined it.
A) If I try to use it in other model it does not show it in the designer
B) If i define it in the other models I get error History already defined
Is there any solution so that the History complex type, defined in one model can be reused by other models?
I was trying to do almost the exact same thing (my DB fields are "created", "creatorId", "modified", and "modifierId", wrapped up into a complex type RecordHistory) and ran into this question before finding an answer...
http://msdn.microsoft.com/en-us/data/jj680147#Mapping outlines the solution, but since it's fairly simple I'll cover the basics here too:
First create the complex type as you did (select the fields in the .edmx Designer, right click, select "Refactor into New Complex Type")
In the .edmx Designer (NOT the Model Browser) right click on another table/entity that has the same common columns and select Add -> Complex Property
The new property will be assigned a complex type automatically. If you have more than 1 complex type, edit the new property's properties and set the Type appropriately
Right-click on the table/entity again (in either the Model Browser or Designer) and select Table Mapping
Update the Value/Property column for each of your common fields (changing them, in my case, from "modified : DateTime" to "history.modified : DateTime")
Delete the old common fields from your entity, leaving just the complex type in their place

Entity Framework, ado.net Data Services, odata

I'm very new to Entity Framework, that's my disclaimer! I have a SQL 2008 database with 2 tables, tblModel and tblHairColor. tblModel contains a column named hairID which is a foreign key to the tblHairColor table's primary key of id.
I created the ado.net entity data model and now, following http://msdn.microsoft.com/en-us/library/dd728283.aspx, trying to access my data resources created.
My URL of http://localhost:51157/WcfDataService.svc/tblModels(1)/modelname/$value works great by returning the model's name (of record 1) from the tblModels table. However, when I try to access the hair color via http://localhost:51157/WcfDataService.svc/tblModels(1)/modelname/tblHairColor it does not work, (http 404 not found).
My entity model, generated from my SQL database, created a tblModels navigation property in tblHairColor and a tblHairColor navigation property in tblModel. It also auto generated an association of tblHairColor to tblModel (1 to *). I expected 1 to 1.
My question is what needs to be added/changed to allow this query, http://localhost:51157/WcfDataService.svc/tblModels(1)/modelname/tblHairColor, to return the models hair color?
Thanks in advance for your time.
Bob
modelname should not be used in URL, just navigational property:
http://localhost:51157/WcfDataService.svc/tblModels(1)/tblHairColor
If you want both model and haircolor, you should use $expand:
http://localhost:51157/WcfDataService.svc/tblModels(1)?$expand=tblHairColor

Adding a property to an Entity Framework Entity from another table

I'm just starting out with the Entity Framework and ADO.NET Data Services and I've run into an issue that I can't seem to figure out. I have two tables, one that has user information and the other that has a created by field. Within the database, there isn't a foreign key between these tables. The user table contains an arbitrary Id, a username, and a display name. The created by field contains the user's username. In my entity I would like to have the user's display name since this is what I need to display and expose over the ADO.NET Data Service? I'm aware that I could restructure the database, but I was hoping that I could do the join using the username as I would in a SQL statement.
Thanks in advance,
-Damien
You can make a view using a join of both tables, and then use this object to display the user's name.
There's some info on mapping custom queries here.