Code sample: Database V5: Precompiled Queries


C# (linq) public

static readonly Func<DatabaseApp, Guid, IEnumerable<gip.mes.webservices.MaterialStock>> s_cQry_GetMaterialStock =
EF.CompileQuery<DatabaseApp, Guid, IEnumerable<gip.mes.webservices.MaterialStock>>(
    (dbApp, MaterialID) =>
        dbApp.MaterialStock
            .Where(c => c.MaterialID == MaterialID)
            .Select(c => new gip.mes.webservices.MaterialStock()
            {
                MaterialStockID = c.MaterialStockID,
                StockQuantity = c.StockQuantity,
                DayInward = c.DayInward,
                DayOutward = c.DayOutward,
                MonthInward = c.MonthInward,
                MonthOutward = c.MonthOutward,
                MDReleaseState = new gip.mes.webservices.MDReleaseState()
                {
                    MDReleaseStateID = c.MDReleaseStateID.HasValue ? c.MDReleaseStateID.Value : Guid.Empty,
                    MDNameTrans = c.MDReleaseState != null ? c.MDReleaseState.MDNameTrans : ""
                },
            })
);

public MaterialStock ExamplePrecompiled(Guid materialID)
{
    using (DatabaseApp dbApp = new DatabaseApp())
    {
        return s_cQry_GetMaterialStock(dbApp, materialID).FirstOrDefault();
    }
}

Modifier: Mario Žitković / Modified:09.08.2023 08:28