Pergunta

I have a RadGridView which I populate like this:

public MainWindow()
{
    InitializeComponent();
    Occupations = _dbContext.Occupations.ToList();
    DataGrid.ItemsSource = Occupations;
}

The Occupation entity class looks something like this (properties removed for brevity):

public partial class Occupation : XTimeEntity
{
    public Occupation()
    {
        this.BUSCOMPLs = new List<BUSCOMPL>();
        this.EMPLOYEEs = new List<EMPLOYEE>();
    }

    public short OccupationCodeId { get; set; }
    public short SiteCodeId { get; set; }
    public short OccupationActive { get; set; }
    public string OccupationName { get; set; }
    public virtual ICollection<BUSCOMPL> BUSCOMPLs { get; set; }
    public virtual ICollection<EMPLOYEE> EMPLOYEEs { get; set; }
}

When the code runs, on the last line of MainWindow I get the errors (SqlException):

Invalid object name 'dbo.OccupationBUSCOMPL'

Invalid object name 'dbo.OccupationEMPLOYEE'

Surely these collections should have nothing to do with the column creation of the RadGridView? It should only include OccupationCodeId through OccupationName. I have never found this issue on other grids. What could cause this?

Foi útil?

Solução

According to Telerik...

The default behavior of RadGridView control is to generate its columns automatically based on the underlying data source. This means that when you set the ItemsSource of the RadGridView control to a collection of employees for example, a separate column will be created for each one of the public properties of your Employee object. This is the default behavior and it does not require any additional efforts from your side. Just set the ItemSource of your RadGridView and you are ready.

source: http://www.telerik.com/help/wpf/gridview-columns-defining-columns.html

Therefore all your properties will be automatically generated. If you read this page (and the rest of the documentation) it states quite clearly how to generate the columns you need.

A quick edit.. This guide will also help point you to a QUICK way to "Not auto-generate a column" http://www.telerik.com/help/wpf/gridview-prevent-column-autogenerate.html

Cheers.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top