MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.26k stars 21.43k forks source link

Migration from in process to isolated Azure Entities #117317

Open alexander-kastil opened 11 months ago

alexander-kastil commented 11 months ago

I found it quite hard to migrate from a very common sample to migrate. My VSCode did not recognize the new attributes. Can you document which .Net Version, Packages, Function Template you are using or provide a link to a running sample please?

[FunctionName(nameof(DurableBankAccount.BankAccount))] public static void BankAccount([EntityTrigger] IDurableEntityContext context) { switch (context.OperationName.ToLowerInvariant()) { case "deposit": context.SetState(context.GetState() + context.GetInput()); break; case "withdraw": var balance = context.GetState() - context.GetInput(); context.SetState(balance); break; } }

[FunctionName("UpdateBalance")] public static async Task Run( [HttpTrigger(AuthorizationLevel.Function, Route = "bankAccount/updateBalance/{entityKey}/{amount}")] HttpRequestMessage req, [DurableClient] IDurableEntityClient client, string entityKey, string amount) { var entityId = new EntityId(nameof(BankAccount), entityKey);

if (req.Method == HttpMethod.Post)
{
    await client.SignalEntityAsync(entityId, "deposit", amount);
    return req.CreateResponse(HttpStatusCode.Accepted);
}
else if (req.Method == HttpMethod.Delete)
{
    await client.SignalEntityAsync(entityId, "withdraw", amount);
    return req.CreateResponse(HttpStatusCode.Accepted);
}
return req.CreateResponse(HttpStatusCode.OK);

}


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Naveenommi-MSFT commented 11 months ago

@arambazamba Thanks for your feedback! We will investigate and update as appropriate.

alexander-kastil commented 11 months ago

Some how a bit of information is missing in your docs ... VSCode is reporting: The attribute 'EntityTriggerAttribute' is a WebJobs attribute and not supported in the .NET Worker (Isolated Process).

host.json

{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" }, "enableLiveMetricsFilters": true } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*, 5.0.0)" } }

image

alexander-kastil commented 11 months ago

Also adding

<PackageReference Include="Microsoft.DurableTask.Generators" Version="1.0.0-preview.1" />

does not help ... Having a sample that compiles would help a lot to get the initial setup done!