AutoMapper - Retrieve a different field from a linked source table than the one that links it - automapper

I have the following table structure that mixes legacy fields with an updated schema:
Coaster
Id (Int)
ParkId (Int)
Park
Id (int)
UniqueId (Guid)
So, the Coaster and Park tables are linked using the Park.Id field. The UniqueId field is not currently used in the old schema. We are migrating to a clean DB using AutoMapper, and this new schema looks like this:
Coaster
Id (Int)
ParkId (Guid)
Park
Id (Guid)
The problem I am having is doing this using AutoMapper. I've been experimenting with this code:
private ModelMapper()
{
Mapper.Initialize(x =>
{
x.AddProfile<ConvertersMappingProfile>();
});
}
// This is the part that I'm trying to work out
public ConvertersMappingProfile()
{
CreateMap<Park, NewSchema.Park>()
.ForMember(dst => dst.Id, map => map.MapFrom(src => src.ParkId));
}
In the new schema, the Park table's Id matches the old schema's UniqueId.
My question is: Because in the old schema there is no direct link to the UniqueId value of the Park table, how to do I get that value to map to the new schema using the Coaster.ParkId field to Park.Id field mapping?

I used a custom resolve to fix the problem. So I created my resolver, which pulls up a list of the items in the database (which is typically pretty small) to get all the values from the table I need, and retrieves the value. (Pre-refactored code):
public class ParkResolver : IValueResolver<Original.Park, New.Park, string> {
public string Resolve(Original.Park source, New.Park dest, string destMember, ResolutionContext context) {
List<Original.Park> list = new List<Original.Park>();
using (IDbConnection con = new SQLiteConnection(#"Data Source=C:\Users\Me\Documents\Parks.sql;")) {
con.Open();
list = con.Query<Original.Park>($"SELECT * FROM Parks WHERE Id = {source.ParkId}").ToList();
con.Close();
}
return list.FirstOrDefault().UniqueId;
}
}
And I call my custom resolver for the tables I am mapping:
CreateMap<Original.Park, New.Park>()
.ForMember(dst => dst.ParkId, map => map.MapFrom(new ParkResolver()));
Hopefully that will help someone else.

Related

Get SharePoint item from document library based on custom metadata

I am storing metadata with my documents and folders in SharePoint. This metadata includes an itemid which is a unique identifier from the system it came from. Is there a way to retrieve the item from SharePoint using Graph API by specifying the itemid in the metadata?
This query works for properties that Microsoft provides like name:
https://graph.microsoft.com/v1.0/sites/{siteid}/drive/root/children?$filter=name eq 'Z'
But if I try it with the custom property then I simply get an empty result:
https://graph.microsoft.com/v1.0/sites/{siteid}/drive/root/children?$filter=itemid eq 'Z'
Is there a way to query documents and folders with custom properties like this?
Here is the code used to update the field on the document in SharePoint using Graph API:
public FieldValueSet UpdateListItem(string siteId, string driveId, string fileItemId, Dictionary<string, object> additionalData)
{
var updateFileTagsRequest = graphClient.Sites[siteId].Drives[driveId].Items[fileItemId].ListItem.Fields.Request();
var fieldValueSet = new FieldValueSet { AdditionalData = additionalData };
var result = updateFileTagsRequest.UpdateAsync(fieldValueSet).Result;
return result;
}
The dictionary values being passed to the UpdateListItem method are strings and look like this: "ItemId", "A unique value"

Azure CosmosDB/Nodejs - Entity with the specified id does not exist in the system

I am trying to delete and update records in cosmosDB using my graphql/nodejs code and getting error - "Entity with the specified id does not exist in the system". Here is my code
deleteRecord: async (root, id) => {
const { resource: result } = await container.item(id.id, key).delete();
console.log(`Deleted item with id: ${id}`);
},
Somehow below code is not able to find record, even "container.item(id.id, key).read()" doesn't work.
await container.item(id.id, key)
But if I try to find record using query spec it works
await container.items.query('SELECT * from c where c.id = "'+id+'"' ).fetchNext()
FYI- I am able to fetch all records and create new item, so Connection to DB and reading/writing is not an issue.
What else can it be? Any pointer related to this will be helpful.
Thanks in advance.
It seems you pass the wrong key to item(id,key). According to the Note of this documentation:
In both the "update" and "delete" methods, the item has to be selected
from the database by calling container.item(). The two parameters
passed in are the id of the item and the item's partition key. In this
case, the parition key is the value of the "category" field.
So you need to pass the value of your partition key, not your partition key path.
For example, if you have document like below, and your partition key is '/category', you need to use this code await container.item("xxxxxx", "movie").
{
"id":"xxxxxx",
"category":"movie"
}

Azure Search not returning document ID

Im using azure search. I have my id field set as retrievable yet its not getting returned in my search results. Do you guys know why? I only see: document object -> key value, in the search result of an individual document. (Im using the .net SDK)
I want this ID to do a document lookup and serve the real document to the consumer.
public static DocumentSearchResult GetSearchResult(ISearchIndexClient indexClient, string searchTerm)
{
SearchParameters parameters;
DocumentSearchResult results;
parameters =
new SearchParameters()
{
Select = new[] { "content" }
};
results = indexClient.Documents.Search(searchTerm, parameters);
return results;
}
I found out that i could put ID in searchparameters to retrieve it. This feels unnatural though..
I found out that i could put ID in searchparameters to retrieve it.
parameters =
new SearchParameters()
{
Select = new[] { "content", "id" }
};
As a side note: to serve the document to the caller you need to add the metadata_storage_path to the index (and to the searchparameters to retrieve it as a searchresult)!
https://learn.microsoft.com/en-us/azure/search/search-howto-indexing-azure-blob-storage

Droidparts: how to get to autocreated column names in m2m table?

community.
I am just start to use droidparts.
As I got it is cool library. But it has poor documentation, and no comments in code itself.
I am interested in getting elegant approach to use it.
Well suppose, i've created tables items, users, items2users as many-to-many concept.
Tables items and users are trivial. Table items2users is
#Table(name="items2users")
public class ItemsToUsers extends Entity {
#Column
public Item item;
#Column
public User user;
}
So if I need to get answer if my User has Item I do something like that in UserManager class:
public boolean hasItem(Item item) {
Select<ItemsToUsers> select = select().columns(ID).where({HERE_I_NEED_COLUMN_NAME}, Is.EQUAL, user.id);
}
Droidparts made table with fields 'item_id' and 'user_id'. As I understand HERE_I_NEED_FIELD_NAME must be 'user_id'. As I realize it is automatic naming model for this situation?
Well is there some elegant technique to achive this names or I should construct them manually getting 'user' and '_' and 'id'?
By default the column name will be field name + _id, e.g. item_id & user_id in your case. That can be altered through annotation, e.g. #Column(name="some_other_name").

Get TaskID for Case Activities

I was getting TaskID for Case Activities (Screen ID - SP203010) using Acumatica Web API. Now after upgrading it to version 6.0, I am not getting that. I have also tried different properties available but seems nothing is getting me that TaskID.
I am storing these activities into my database pulling from Acumatica Partner Portal and to avoid duplicate activities being imported, I was comparing it with TaskID.
Below is the code snippet I am using to get TaskID
SP203010WS.Screen context = new SP203010WS.Screen();
context.CookieContainer = new System.Net.CookieContainer();
context.AllowAutoRedirect = true;
context.EnableDecompression = true;
context.Timeout = 1000000;
context.Url = "https://sso.acumatica.com/Soap/SP203010.asmx";
PartnerPortalCreds loginCreds = GetCreds();
string username = loginCreds.PARTPRTUSE;
string password = loginCreds.PARTPRTPAS;
SP203010WS.LoginResult result = context.Login(username, password);
SP203010WS.Content content = context.GetSchema();
context.Clear();
string[][] export = context.Export
(
new SP203010WS.Command[]
{
new SP203010WS.Value
{
Value = currentAcumaticaCaseNo,
LinkedCommand = content.Case.CaseID
},
content.Activities.Type,
content.Activities.Summary,
new SP203010WS.Field { FieldName="Body", ObjectName="Activities"},
content.Activities.StartDate,
content.Activities.CreatedBy,
new SP203010WS.Field { FieldName="TaskID", ObjectName="Activities"},
},
null,
0, true, true
);
Let me know whether it has been moved or deprecated in newer version. What shall I be using instead of TaskID or where can I find that TaskID.
In Acumatica 6.0 table EPActivity was splitted on CRActivity, SMEmail and PMTimeActivity. Original table was renamed to Obsolete_EPActivity.
Now NoteID is the key field on all tables. SMEmail and PMTimeActivity contains RefNoteID field - foreign key from CRActivity.
You may find value pair TaskID and NoteID in table - Obsolete_EPActivity
#Krunal, as Ken mentioned, after upgrade to 6.0 value pair TaskID and NoteID is only available in the Obsolete_EPActivity table. One should use Obsolete_EPActivity table to replace obsolete TaskID integer values with actual NoteID GUIDs.
There is no way to access Obsolete_EPActivity table through Web Services. After upgrade to 6.0, Acumatica inserts new Activities only in the CRActivity table.
To avoid duplicate activities, you have to store actual NoteID GUIDs in your database instead of obsolete TaskID integer values and compare GUIDs while importing records.
For previously imported activities you will also have to replace TaskID values with actual NoteID GUIDs. Searching for CRActivity record based on CaseID, Subject and CreatedDateTime field values stored in your DB, you should find appropriate record and use its NoteID to replace legacy TaskID value.

Resources