About Data Dictionary - x++

I'm working with Dynamics ax 2012.
I'm finding a way to create foreign key with dynamics ax.
I try to create new -> relation -> new -> foreignkey -> primarykey based
I successfully created this relation but when I look the database in SQLSERVER2008 i think ((the relation)) the foreign key is not created !
And what about the primary key !! what can i do to create my personal key other then "RecId" !!
If one day i want to import a database created with SQLSERVER2008 to Dynamics AX will it be possible ? and how do I do that ?

Sorry but table relations are for the benefit of the AX environment, it is not synced to the database. Basically only fields and indexes are synced.
Can you make an AX database from an SQL database?
It probably could be done using a good deal of X++ programming doing ODBC reads from the source database meta tables. I don't know if anyone have tried it, but I doubt it.
You are most likely better off by a total database redesign, as the AX data dictionary contains more information than the SQL database.
How would you convert an SQL Database to use Valid Time State Tables and Date Effective Data?

Related

How to mark data as demo data in SQL database

We haave Accounts, Deals, Contacts, Tasks and some other objects in the database. When a new organisation we want to set up some of these objects as "Demo Data" which they can view/edit and delete as they wish.
We also want to give the user the option to delete all demo data so we need to be able to quickly identify it.
Here are two possible ways of doing this:
Have a "IsDemoData" field on all the above objects : This would mean that the field would need to be added if new types of demo data become required. Also, it would increase database size as IsDemoData would be redundant for any record that is not demo data.
Have a DemoDataLookup table with TableName and ID. The ID here would not be a strong foreign key but a theoretical foreign key to a record in the table stated by table name.
Which of these is better and is there a better normalised solution.
As a DBA, I think I'd rather see demo data isolated in a schema named "demo".
This is simple with some SQL database management systems, not so simple with others. In PostgreSQL, for example, you can write all your SQL with unqualified names, and put the "demo" schema first in the schema search path. When your clients no longer want the demo data, just drop the demo schema.

Get the schema from an SqlEntityConnection

I want to fetch information from 1 table (Using OdbcConnection to fetch information) and insert it within a sql server that I connect via the SqlEntityConnection type provider.
I want to do a simple validation where I will compare the columns name and columns type of the tables in both databases. I've been looking around and can't find a way to fetch the columns name and columns type from
let EntityConnection = SqlEntityConnection<ConnectionString="...">
I am able to fetch information from the table I want but I don't think I can access INFORMATION_SCHEMA, so I'm a little bit loss as to how I can fetch this information.
Thank you.

How should I handle maintaining row Identity for new records in Linq / Entity Framework?

What is the proper way to create a new unique shared key when using Linq and EF with SQL?
I could use a GUID upon inserting the record but I only want want my keys to have 7 digits or characters in it as they will appear in the URL of my MVC application. If this isn't an option, or it's just better with GUID's let me know.
If you do not need a unique key across machine boundaries then I would just go with a bigint/idenity that auto-increments by 1 (which is the default). You do not have to specify the identity when adding a new entity with EF, it will be auto-assigned. Once it has been assigned you can then use it as a FK.
In my opinion GUIDs are only useful in this context if you have to guarantee that the key is unique across multiple databases, i.e. you create they key on one machine (A) and want to transfer the data to another machine (B), retaining the key. This is not possible with bigint keys since machine B might have inserted other data with the same key already.

EF4 - Is there any way it can be made to support unique indexes

My primary key is a guid column and I would like to have a unique index on another column in the table. I read that EF4 doesn't do anything for unique indexes. My question is: Can I add to a partial class any code that would allow me to check for non-unique values before my data hits the database. Currently I'm using the following configuration:
Users Desktop <> wpf Datagrid <> Observable Collection <> EF4 <> SqlCe database.
Thanks in advance.
Richard
I don't think it can do this, because to track value uniqueness entity framework requires all records from the table to be read into memory, or execute database query on each value change. It is performance-ineffective way and I think entity framework does not support this.
Supporting unique key concept is definitely in scope for the next version of EF from what i have heard. But uniqueness will be enforced at the objectcontext level meaning what is currently tracked in the object context. This is the same concept for cascading delete which currently works in EF4. In cascade delete, EF only enforces cascade deletes to entities that is currently loaded in the objectcontext. It does not try to load everything from the database.

Handling lookup tables in Entity Framework v1

I am just getting started with Microsoft's Entity Framework, using it for an MVC project since MS seems to be really pushing it, and I'm running into some issues. In my database there are multiple lookup tables tied to a single table via foreign keys. Within the entity framework I am trying to combine these into one so that I have a simplified single view for this data in my model. However, this doesn't seem possible from the designer view. Is there something obvious I'm missing? Is there a way that I can edit the edmx file manually to produce this sort of model?
At the moment, Foreign keys and lookup tables in Entity Framework are a PAIN.
EF with LINQ makes getting your data super-easy, and on the surface it looks easy to update, but with lookup tables things get difficult (for now... read on...)
I'm not sure how you would "combine" your lookup tables into a single table. If each table contains a different type of "lookup entity" then IMHO they should be represented separately in your EDM. I'm guessing you're having headaches updating a record's foreign keys to the lookup tables. That's because it is a headache.
Changing foreign key values:
MyDBEntities _db = new MyDBEntities();
//get a Person
MyDBEntities.Person person = (from p in _db.Persons
where p.Id = 1
select p).First();
// This sets the foreign key value in the Person table on the PersonType field
person.PersonTypeReference = new EntityKey("MyDBEntities.PersonType", "PersonTypeId", 3)
The next release version of the Entity Framework will have a new concept called "FK Associations." This will bring back the sanity of setting the foreign key value directly rather than having to create and set an EntityKey.
HTH.

Resources