Inaport Lookups can't find target entity - CRM4 Connector - dynamics-crm-4

The documentation for inaport states you can just map lookup fields and it will work out what types they are.
I am mapping from CRM 4 to CRM 2011 (using the CRM Connectors), however all my lookups fail with
A lookup value was mapped to account.{field name} but no target entity name was supplied and no default is available.
I have to fall back to adding a custom field, checking if their is a lookup id in the field, and then making a lookup value as per the documentation of guid::entityname using expressions which is painful.
Is this feature working for anyone else? Do i need to set up a child-parent relationship? I only ever add a map for the entity I'm working on.

Inaport will try to work out what the correct entity reference is and default it. For example, if the lookup is the foreign key in a child table, the entity reference will default to the parent.
There are some circumstances where a lookup may reference multiple entity types, and Inaport cannot infer the correct type. For example, and activity "regarding" lookup may reference 12 different entity types.
It could do a better job when a custom lookup is only referencing a single entity type, and a change request has been put into the system.
As you noted, when Inaport does not correctly infer the entity type you can force it by appending "::entityname" to the GUID you are mapping to the lookup field. This is discussed in more detail in the help.
HTH
Regards
David Evans

Related

Is JpaRepository.save() suitable for entities with auto generated IDs if we want to UPSERT them?

I'm facing a problem with duplicate records in a MySQL database when I'm upserting using JpaRepository.saveAll() entities which are already present in the database. I want new entities to be inserted, existing ones to be updated(if there are changes to any of the properties), otherwise no action is expected.
The entity classes id property is annotated with #GeneratedValue(GenerationType.IDENTITY) and the id column in the corresponding table in MySQL has auto-increment enabled. I'm pointing that out because JpaRepository.save(), which is invoked for each entity in saveAll(), does a check by id if the entity is already present in the database.
Here is where in my opinion the contradiction between save(), when used for updating, and auto-generation of IDs occurs: You can't update existing records because all of the entities passed into saveAll() will have newly generated IDs and thus the check in save() will always say that they are not present in the database.
Is my logic correct?
The only solution to the problem that I can think of is to create a custom query that compares the records in the database with the newly passed entities by the values of another column whose values are unique. I can't compare them by id because I will encounter the same problem as in save().
Is that good enough and are there any other solutions?
Depending how you look at it, your are either wrong or right.
What you describe in terms of behaviour is correct: If you pass in an entity with id set to null to save you will always create a new row in the database and never perform an update. In that sense you are correct. That behaviour is independent of how the id gets generated for new entities.
But the id of an entity defines its identity. If two entities have the same id they represent the same row in the database thus the same logical entity and the behaviour of save is exactly that of an upsert. This is also independent of how the id gets generated for new entities.
If you want an upsert based on a different column (or columns) you need to write custom code, for example using an actual upsert statement in a query annotation. Alternatively you can try to load the entity by the columns in question and if you succeed set its values as desired and otherwise create a new entity and save that.

SQL ENUM is it possible to save few enum values in table

I need to create a water tourism portal and I am thinking: Is it possible to save in a table some values from enumerable?
For example, track can have different types of boats: kayak, boat, canoe. So the person who creates a track can choose that track is valid only for one of the types or 2 or 3. How can I store this data? I am thinking about enumerator but I am not sure if I will be able to store this data in a table.
While there is an ENUM type, I generally recommend against using it. It has some unconventional behavior at times (you can reference values by index, and the data type is not handled well by many APIs), and modifying the list of values requires altering the table structure (which requires rebuilding the table, data and all, behind the scenes).
You are much better off creating a lookup table with the enum int value as an id and a string for the values' names. Your "tracks" table can just reference that, as can whatever interface you provide for users to select a boat type. Using an ENUM would mean you either have to the boat types embedded in code behind the user interface, that you then have to coordinate with the the enum values in the table definition; or querying the table structure, and parsing the data type for the "boat type" field.
Note: If different types need different handling, it can be very helpful to have a code enum mirror such a lookup table, or rather have a lookup table reflect a code enum, then the lookup table mainly serves to enforce data integrity on the database side, and to aid in displaying the data in a user intelligible way.
Also, keeping future expansion in mind, if the tourism portal later decide to start facilitating rentals, the boats that can be rented will likely have types; so you either have to duplicate the ENUM, or just reference the same lookup table.
The functionality you're looking for is provided by the SET data type, which lets you assign to a column zero or more elements from a given set of (no more than 64) elements (see documentation).
Recommendations from Uueerdo still apply, of course.

How to refer to hardcoded values in code from the database?

In the (MySQL) database, I'm storing a view hierarchy, with each row in a table referring to a single view. There are several types of views, but they're stored in the same table.
In the application code, each type of view has its own class. Each row in the database instantiates one of these classes.
How should I refer to these classes from the database, so the application knows which class to use?
I can think of several possibilities:
Just specify the class name directly in the table, but this has the disadvantage of having to change lots of rows if the class name changes (which can be done in a single query if required).
Have a separate table storing class names, and use foreign keys to point to the row storing the correct class name. In this case, I could forgo having an ID field in this lookup table and instead have the class name as the primary key and target foreign key, and rely on a cascading UPDATE if the class name changes?
Are there better options available?
If I understand correctly you want to maintain an association between view-names and class-names.
Your bullets suggests, that there can be more than one view for the same class and both of your suggestions would work. The second bullet has the advantage that you can change the class name with a single update. But that doesn't buy you much, because as soon as more than just a single class-name changes, i.e. when the association itself changes, you need to update more than one row.
You might even create a separate table, holding this association. This would be the model for an n:m relationship, which is too general, so you'd have to place a unique constraint on the view-name. Essentially this will just factor out the concern of associating view-names with class-names and allow you to change this mechanism entirely without having to mess with your tables (except the one holding this association).
But actually I would not store any of this stuff in the database
(I also find it irritating that view-names are stored in the database and not in the application logic). The fact that there are class-names, should be of no concern to your database. This is application logic and it should be handled there. So what you need is a way to instantiate an object when the view-name is known. This looks like a classic factory to me. After all, if a class name changes, it is a change in the application code and life is easier, when all resulting changes lie in the application code as well.

MVC 2 EditorForModel() rendering foreign key table names

I have an interesting problem and wanted so see if anyone else has seen this. I've created a MVC 2 site using Visual studio 2010 beta 2. I'm using linq to sql data model objects with data annotations.
In my data model objects I'm using [ScaffoldColumn(false)] attribute to exclude the foreign key ID's from rendering to the UI when I use the EditorForModel method. For some reason the UI is rendering the foreign key table name.
e.g. if the foreign key is AccountID, i see the "account".
I wonder if this is a bug in the editorformodel or if I need to use a different/additional data annotation attribute to instruct editorformodel to not render anything.
You Linq to SQL classes will have a property for the foreign key itself (AccountID) as well as an EntitySet property for the related records in the Accounts table. If you open up the auto-generated designer.cs file under your linq to sql dbml - you can view all the properties of each class. I think by default the templated helpers are only supposed to generate an editor for the first level of properties. There is a "deep-dive" option that will extend the generated editor to more levels of properties. Check out Brad Wilson's blog on the subject (near the end of the post).
In general, trying to throw your auto-generated Linq to SQL classes into your View or annotate them with attributes gets pretty hairy. It might be worth checking into strongly typed view models where you could specify only the properties you're interested in displaying in your view.

Linq To SQl Reference Keys behavior?

I have a database with some references,
An example is a Customer Table has the AddressId integer column, and an Address Table has the Idenity Auto Generated Id column. I reference these as primary the Address "Id" and the Customer "AddressId". Now when i generate the dbml file or use SqlMetal, i get in the Customer entity two properties for the reference, AddressId that is an int type, and Address as an Address type. This is confusing! can i get rid of this functionality?
And how could i turn off pluralize? Thank you.
You cannot turn off the 'feature' of generating both the foreign entity reference and the foreign key reference. L2S uses both of them in conjunction. So, you're going to have to get used to it. It was a little hard for me to get used to at first, but I then realized there are benefits to having both.
If I recall, SQLMetal has a command line option to turn off pluralizing, but cannot say for sure. I wrote my own code generator that generates my entities and data context object and I have it generate non-plural names.