You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That would be nice. Unfortunately, there is nothing in the signature that would let TypeScript infer the result type. At some point you would have to specify the type. For example via the query.
let query = EntityQuery.from<Customer>('Customers').orderBy('companyName')
I'm not sure that would make it any better, though. This used to work w/o having to cast, but TypeScript has gotten more strict and now we are forced to cast.
Making EntityQuery.from() generic is exactly what seems to be the best option here from my point of view.
I'm thinking of how it's implemented in EF, for example, here:
using (AdventureWorksEntities context =
new AdventureWorksEntities())
{
string esqlQuery = @"SELECT VALUE Contact
FROM AdventureWorksEntities.Contacts as Contact where Contact.LastName = @ln";
// The following query returns a collection of Contact objects.
// ---------------- See the following line ---------------------------------------------
ObjectQuery<Contact> query = new ObjectQuery<Contact>(esqlQuery, context, MergeOption.NoTracking);
// -------------------------------------------------------------
query.Parameters.Add(new ObjectParameter("ln", "Zhou"));
// Iterate through the collection of Contact items.
foreach (Contact result in query)
Console.WriteLine("Contact First Name: {0}; Last Name: {1}",
result.FirstName, result.LastName);
}
Also in my opinion, introducing type parameters makes API cleaner by explicitly demonstrating that a method is supposed to return specific type as requested by a caller.
Also, I'd like to make the same proposal regarding EntityManager.createEntity() method and maybe some other similar methods which I'm not familiar yet.
When I'm trying a code like in the example from README.MD:
It doesn't compile with an error:
So I have to cast it to through
any
to the actualEntity
type it supposed to return:.then(res => res.results (res.results as any) as Customer[])
Can we change this method signature to return an actual entity type instead of
Entity
?The text was updated successfully, but these errors were encountered: