mapping xml to object via linq - linq

I'm trying to run linq on xml and map to my object type, but some of the fields in the xml don't exist for some records. For example a phone number field exists most of the time for each customer in the xml file, but sometimes that tag won't exist at all. How can I check for the existence or not while mapping the data to my object via linq?

Related

Loading Lookup Data into Model Driven PowerApps Custom Entities

I am trying to upload 1000s of records into a custom entity on model driven Power Apps. I am able to read in text fields, option sets, dates, etc without any issue. However when I try to map lookup fields, I get an error that says "can't resolve the guid for the lookup field:...". I am able to select "Edit in Excel" in an entity where I can manually select the appropriate lookup choice. But i can not copy and paste the item name because it does not recognize it as a GUID. There is too much data to do this and I need a way to complete this in a programmatic way.
I essentially want to relate the Product IDs (500004, 500370, etc) to the POBs (POB-1000, POB-1001, etc), as records that I can connect together in the model driven app.
Error message after mapping fields and importing:
By default, while importing in CRM (aka Model driven Power App), Lookup field will expect either GUID of that record (ex. 78C03F0D-4618-41C6-9089-B5BDB456465A) or Name (Primary field of that entity record, ex. Full name) to resolve the particular record to be associated.
If you want to map another field, you can map it while doing mapping in Import wizard.
How To Set A Lookup Value With Non-Primary Field As Reference

Nesting a table with POJO data sources in BIRT

I have a POJO data source that has several output columns, one of which is a Java Object (ArrayList). I can access this in my table but want I want to do is have a nested table that displays information from this Java Object (it is a list of objects). Something like a purchase order form that has purchased items in a table... Trying to figure out how to get started on this.

How do you expose a Web API OData service that returns a combination of Entity Framework and File System results?

For example, I have a database table that contains the following fields:
ID
Type
FilePath
An Entity Framework model is created for that table. The model is used to create an EDM for an OData service.
I would like to use that Odata service to filter the database fields as well as filter the results based on the content of the files located at the file path.
For example I'd like to be able to use syntax like this to get all records where the Type starts with the word 'procedure' and the content contains the word 'test':
$filter=startswith(Type,'procedure') and substringof('test', FileContent)
I would like the database filters to be applied first so that there are less FileContents to read. I would also like to read the FileContents one by one using a stream instead of loading them all into memory.
Can this be accomplished through LINQ by creating some sort of IQueryable object?
Can this be accomplished through Web API OData by attaching a property to the EDM and treating it differently?
It may be resolved in this way:
Add a property, say Content to the entity type.
Derive ODataQueryOptions and overwrite its ApplyTo method. This is the base class:
https://github.com/ASP-NET-MVC/aspnetwebstack/blob/master/src/System.Web.Http.OData/OData/Query/ODataQueryOptions.cs
Use the derived class in the controller:
public XXXXXController
{
public IHttpActionResult(MyODataQueryOptions options)
{
var products = this.GetProducts().AsQueryable();
return Ok(options.ApplyTo(products));
}
}

Assigning values to unmapped property

Suppose, I have a Customer class with some properties like
name,
id,
object of CompetentAuthority class etc.
name,id etc is mapped in .hbm file but i have taken icollection of CompetentAuthority object and I didnt do any entery in .hbm file for CompetentAuthority(one-to-many).
In CompetentAuthority class i have taken Customer object and in .hbm file of CompetentAuthority i did many-to-one relationship.
Nnow,i want list of customers with it's CompetentAuthority list but as its just an object and no mapping is done,criteria API doesn't allow me to do innerjoin;it gives me error like "cannot resolve property"
Is there any way to achieve this.
If you are wanting to use the Criteria API to apply an INNER JOIN, then no you cannot do that. The CompetentAuthority object needs to be mapped with NHibernate and the Customer object's mapping file will need to be modified to establish the relationship between the two entities.
If for some reason you are not able to map the CompetentAuthority, you could take advantage of mixing the ISession.CreateSQLQuery() method and the Transformers.AliasToBean() method which will allow you to hydrate an unmapped entity.
For more information on this technique, please refer to the Official NHibernate documentation section titled "Returning non-managed entities" or search around for using the AliasToBean() method: http://nhibernate.info/doc/nh/en/index.html#d0e11066

Batch insert/update with entity framework

I have a Tags table whose schema consists of only ID and Name (unique). Now, from the GUI user can enter tags for a BlogPost. When the data is saved, with tags stored in an array of string (names), I want to add tags whose names don't yet exist to the Tag table and ignore tags whose names already exist AND get back the list of all tag entities (including the existing and newly added ones). How can I do this in Entity Framework in just 1 SQL roundtrip?
For the returned tags, I want to associate them to the to-be-added BlogPost object (which is just instantiated and not stored in DB via EF yet). Is it still possible that this step can be combined with #1 in 1 single roundtrip or must I have to issue another query?
I don't believe the Entity Framework does batch inserts at all (at present). So if you must keep the number of DB roundtrips so low, you're probably going to have to use a stored procedure or a database trigger. Fortunately, the Entity Framework supports stored procedures which return entity types. There is documentation on MSDN about this. You could create a proc which accepts a string list of tags and returns tag entity instances. Alternately, you could add a VARCHAR column to your post table for a delimited list of tags, and parse it in the trigger.

Resources