samedi 10 octobre 2015

Objet type property not recognized inside LINQ

I have this code:

var siteObject = getObjectModels(context, contractsIDList, date);
var clientObjSitesList = bridgeTable_clientObjModel(models, contracts, clients, siteObject);

private static IQueryable<object> bridgeTable_clientObjModel(
    IQueryable<ObjectModel> objModels,                                                     
    IQueryable<Contract> contracts,
    IQueryable<Client> client,
    IQueryable<SiteObject> siteObject)
{
    var clientObjSitesList = 
        from cn in contracts
        join cl in client on cn.Id equals cl.Id
        join so in siteObject on cn.Id equals so.ContractId
        select new
        {
            clientId = cl.Id,
            modelId = so.ModelId,
        });
}

private static object createClientTypesObjectList(
    IQueryable<Object> clientObjSitesList, 
    IQueryable<ObjectModel> models, 
    IQueryable<Contract> contracts, 
    IQueryable<Client> clients, 
    IQueryable<SiteObject> siteObject)
{
    var clientTypesObjectList = 
        (from cob in clientObjSitesList
         join om in models on cob.modelId equals om.Id into g
         from subpet in g.DefaultIfEmpty()
         select new
         {
             clientId = cob.clientId,
             modelId = cob.modelId,
             typeId = (subpet == null ? -1 : subpet.ObjectTypeId)

         }).ToList();
}

In this function createClientTypesObjectList() in this row:

 join om in models on cob.modelId equals om.Id into g

I get this error:

'object' does not contain a definition for 'modelId' and no extension method 'modelId' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?

As I understand the problem occure because I return object type in this function: bridgeTable_clientObjModel()

Any idea how can I fix the problem?How can I make modelId property recognized in createClientTypesObjectList() function?





Aucun commentaire:

Enregistrer un commentaire