Replies: 8 comments
-
A generic version of EntityReference won't work since there are lookup fields in CDS that can point to more than 1 entity. Think about the customer or regarding lookups. As for the LINQ provider. You can write your own QueryProvider around the CDS Linq provider which translates your expression (with your custom object) to a expression that the CDS linq provider can understand. |
Beta Was this translation helpful? Give feedback.
-
I disagree. This would improve 95+ percent of the cases, where entity references target a single entity. 100% of the custom entities for starters. For the cases where you have exactly 2 ( Also, for the remaining 5% where you can't determine the entity type up front (because it's dynamic, such as
I didn't know this. Is there any sample code to use as a starting point? |
Beta Was this translation helpful? Give feedback.
-
@mathiasbl For the record: I just performed a
Which confirms my ~90%-10% claim. |
Beta Was this translation helpful? Give feedback.
-
On a second thought, I could simply wrap |
Beta Was this translation helpful? Give feedback.
-
From Microsoft's perspective you'd want a solution which fits 100% of the time. Which is what EntityReference brings today. I can agree you might want more fool proof code but imo this shouldn't be part of the SDK. As for the QueryProvider. We created an extension on IQueryable (I know it's not ideal but the EntitySets are IQueryables) which just returns a custom IQuerable implementation which has some additional logic. public static ID365Query<TSource> AsD365Query<TSource>(this IQueryable<TSource> queryable) where TSource : Entity
{
return new D365Query<TSource>(queryable);
} |
Beta Was this translation helpful? Give feedback.
-
Kind of off-topic, but EntityReference also lacks value object properties. It is a class (not struct), but there is no override for equals operator (==).
areEqual is false, which is not any D365 developer would want in 99% cases. Same true for Money type. Taking in mind that any of them might be null simple equality check becomes a monster.
It might get worse without null conditional operator. Is there any chance this could be addressed in the future? |
Beta Was this translation helpful? Give feedback.
-
@fberasategui regarding what your doing with a typecase entityreferance, given that you extended the object, you could add a ISerializable and look at implementing the interfaces there to custom serialized the object back into a normal entity refence. This is similar to how we do a number of things in the wire transport for talking to CDS. Have you explored that? @sergeytunnik, that is something we have discussed a few times for several of our classes. The tradeoff's are that the utility would be diminished if we only added it in the client libs. |
Beta Was this translation helpful? Give feedback.
-
@MattB-msft thanks for the suggestion. One thing though: my class does not inherit from |
Beta Was this translation helpful? Give feedback.
-
@MattB-msft I've given you access to our (private by now) CDS library. I intend to make this public at some point, but we're going thru some internal stuff that needs to get resolved first, and I would like to add documentation to the project too.
That said, if you look here you'll see that I created a generic version of
EntityReference
. This works great and greatly improves type safety, since, for example, anEntityReference<Account>
is NOT the same as anEntityReference<Contact>
, therefore we get compile time safety to not mistakenly assign one another.Unfortunately, the CDS LINQ provider does not "know" my class at all, and therefore is unable to resolve queries like this:
Since it attempts to serialize
contactId
and I get a WCF error saying that's not a known type.I would be awesome if it was supported, so I propose 2 things here:
EntityReference
in the first party SDKsBeta Was this translation helpful? Give feedback.
All reactions