How to map composite db object to clr object that has less properties? - npgsql

We perform a Npgsql upgrade from 2.* to 3.2.7.
I want to map a database object "dbObject" that has fields: a,b,c
to a clr object "clrObject" that has properties: a,b
I define a mapping as follows:
NpgsqlConnection.MapCompositeGlobally("dbObject",someNameTranslator);
And I get a runtime error that states, that clrObject does not have a property that matches "c" field in dbObject.
Is there a way to omit some fields when mapping dbObject to clrObject?

This isn't possible at the moment - Npgsql requires that your CLR object have all the necessary fields/properties to map to the PostgreSQL property. You can open an issue on http://github.com/npgsql/npgsql to request this.

Related

Can I reference an external database as the properties of a model in viewer?

I'm attempting to create an instance of the Forge-viewer API to reference an outside database (Homemade, not bim360 or Fusion) as the Properties of an object selected. (i.e. the database parameters fill-in the properties window) However, I'm unable to find a method. What do you recommend?
The best place to start would be the below code samples:
https://forge.autodesk.com/blog/adding-custom-properties-property-panel
https://github.com/yiskang/forge-au-sample/tree/master/properties
https://github.com/Autodesk-Forge/forge-rcdb.nodejs //interaction with custom data source and many data centric plugins
Basically you will need to customize the model property panel and feed in your own data source by extending Autodesk.Viewing.Extensions.ViewerPropertyPanel and setProperties/setNodeProperties ...

Getting extended properties on users objects

I try to query a user including extended properties:
/users/xxx#xx.dk?$expand=properties
However I get following error:
Could not find a property named 'properties' on type 'microsoft.graph.user.
Is it possible in one request to get a user object with all of it's extended properties?
Best scenario would be something like following where I query for the departmentNumber from the extended properties with direct properties:
/users/xx#xx.dk?$select=companyName,officeLocation,departmentNumber&$expand=properties
This is because, as the message states, there is no property named properties.
How you retrieve custom properties depends on how they were created. There are two types: Open Extensions and Schema Extensions. Each is stored and behaves a little differently so you'll want to refer to the documentation I linked to for help determining which type you want to use.

Is there a way to map properties to column names using some .Insert extension method for Dapper?

I have the following challenge with this class:
Public Class MyClass
Property Id As Integer
Property LastName as String
End Class
The corresponding data table in the database has as fields:
Id (int, not null)
Last-Name (nvarchar(80),null)
So I need to map MyClass.LastName to MyClasses.Last-Name and have a hell of a time...
When I write a custom Insert query it all works, but I would like to use the .Insert statement of one of the Dapper extensions packages.
I tried Dapper.Contrib, but this ignores mappings that I create using Dapper.FluentMap or using the built in method of Dapper itself using Dapper.SetTypeMap.
I tried Dapper.FastCrud, but I was unable to figure out how to configure mappings for it, though this API seems promising.
Anyone?
So, basically the problem here is that the property name and column name is different.
With Dapper, you can handle this by providing alias for column name in SQL query. I guess you have already tried this as you said "I write a custom Insert query" in your question. Other multiple ways to map column names with properties are discussed here.
With DapperExtensions, you can map the different column names with their respective properties something like below:
public sealed class MyClassMapper : ClassMapper<MyClass>
{
public MyClassMapper()
{
Table("MyTable");
Map(x => x.Id).Key(KeyType.WhatYouWant);
Map(x => x.LastName).Column("Last-Name");
AutoMap();
}
}
Code sample is with C#. You have to translate it to VB.NET.
With Dapper.Contrib, you can decorate the class with [Table] attribute to map the table name. Alternatively, you can use SqlMapperExtensions.TableNameMapper to map the tables. Please refer to this blog post or this and this and this SO posts for more details.
Apparently, there is no way to map the column name. This feature is planned for next major (2.x) version. Version 2.x is released; but the issue is still open. Looking at the release notes, feature is not yet added.
With Dapper.FastCrud, there are multiple ways for mapping. You can decorate the property with [Column] attribute.

Spring Data MongoDB default type for inheritance

My model consisted of the following example:
class Aggregate {
private SomeClassWithFields property;
}
Now I decided to introduce inheritance to SomeClassWithFields. This results in:
class Aggregate {
private AbstractBaseClass property;
}
The collection already contains a lot of documents. These documents do not contain a _class property inside the DB since they were stored before the inheritance was present.
Is there a way to tell Spring Data MongoDB to use SomeClassWithFields as the default implementation of AbstractBaseClass if no _class property is present?
The other solution would be to add the _class to all the existing documents with a script but this would take some time since we have a lot of documents.
I solved it by using an AbstractMongoEventListener
The AbstractMongoEventListener has an onAfterLoad method which I used to set the default _class value if none was present :) This method is called before any mapping from the DBObject to my domain model by spring so it works then.
Do note that I also needed to let spring data mongodb know the mappingBasePackage in order for it to be able to read an Aggregate before writing one. This can be done implementing the getMappingBasePackage method of the PreconfiguredAbstractMongoConfiguration class.

Silverlight / .NET RIA Services - Exposing a custom property to the client

I have a table in my database called "Task". Task has the following fields:
- ID
- Description
- AssignedUserID
- TaskTypeID
I am accessing this table through a class that was created automatically after I used an ADO.NET Entity Data Model. I can load and show the fields mentioned above in a DataGrid in my Silverlight application. However, AssignedUserID and TaskTypeID are not very descriptive. So I decided to create a stored procedure that gets the tasks and the user and task type names through their respective lookup tables. This is where the problem lies.
I want to create some custom properties in the automatically generated "Task" class. The custom properties would be named "AssignedUserName" and "TaskType". I then want to make these properties available to my Silverlight client. However, I cannot seem to figure out how to get them exposed to my Silverlight client.
Can someone help?
Thank you
If your EDM is in the same project as the DomainService you can do this:
create a partial class on the Entity type, and add your calculated property in there.
name the file **.shared.cs
it will then be auto-shared with the client/Silverlight code.
Edit:
I was assuming that you could do this calculation in app logic rather than use an sp, which seems more straightforward to me.
If you do use an SP, you'll need to use the Function Import feature in the designer to map the SP to a function in the EDM. This function can then return entities, with properties mapped however you like.
An easier way would be to just use the object model: Have Task.AssignedUser and Task.TaskType objects off of your Task class. Map these to lookup tables in your db. This will work out-of-the box (assuming the Id's are FK's to those lookup tables).
So, a couple options:
use app-logic--properties in a partial class to return the descriptions
use the object model driven by FKs to lookup tables, then just access Task.AssignedUser.Name or Task.TaskType.Description
use a function import to access the SP and map the returned values to entity properties
1 or 2 being the best options IMHO.
Another approach might be to update your EF model to include the lookup tables, add Associations between the tables, add [Include]s in the (auto-gen'd) metadata class and let EF and RIA do it for you. Maybe.

Resources