简体   繁体   中英

Purpose of csdl/edm model for querying an odata dataset?

I had my crm dynamics 2011 instance generate a CSDL model:

在此处输入图片说明

The purpose of this model is so that I can query my dataset via odata.

Is it OK for me to manually delete everything within the CSDL file except for one entity?

The reason I ask is because I have been able to segregate out of this gigantic CSDL model just 1 entity, that looks something like this:

在此处输入图片说明

However queries are not working. Only extremely basic queries with Edm.String work.

As an important side note, I was able to load a subset of the CSDL file, without any errors:

public static IEdmModel GetModel()
{
    if (EdmModel != null)
    {
        return EdmModel;
    }

    IEdmModel referencedModel;
    using (
        Stream csdlStream = File.Open("csdl\\WorkingorgFile.csdl", FileMode.Open, FileAccess.Read,
            FileShare.Read))
    {
        IEnumerable<EdmError> errors;
            var parseResult = CsdlReader.TryParse(new[] {XmlReader.Create(csdlStream)}, out referencedModel, out errors);

        if (!parseResult)
            throw new InvalidOperationException("Failed to load model : " +
                                                string.Join(Environment.NewLine,
                                                    errors.Select(e => e.ErrorMessage)));
    }
    EdmModel = referencedModel;
    return referencedModel;
}

I'm not exactly sure what a CSDL model is, but whenever you're communicating with CRM, it does not require that you know the exact structure of the data. You just can't filter or select an attribute that doesn't exist, or define the filtered attribute as a different type (ie compare a Date to a Money).

CRM also doesn't fully support the OData Querying protocol. You can't for example perform aggregate queries, or join more than 3 layers deep, or filter on multiple entities.

If you're looking for tools in order to help create your queries, I recommend using the FetchXmlBuilder to to build your queries. It will generate the OData call to CRM based on the FetchXml Query you've given it. You can then run them to test that the data is what you desire.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM