开发者

ASP.NET ReportViewer and Linq To Sql Questions

Does the asp.net ReportViewer control work with LinqDataSource? If so are there any examples out there?

Why don't Linq to Sql generated entity classes show up in the Website Data Sources pane, when e开发者_JAVA百科diting a report?


It appears the Website Data Sources pane will only show you all classes that have public methods that return IEnumerable, but it won't show properties, even if they also return IEnumerable. For example, if you have this class:

public class Name

{
    public Name(string firstName, string lastName)
    {
        FirstName = firstName;
        LastName = lastName;
    }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
public class Class1
{
    public IEnumerable<Name> Names { get; set; }

    public IEnumerable<Name> GetNamesList()
    {
        List<Name> list = new List<Name>();
        list.Add(new Name("Al", "Alverson"));
        list.Add(new Name("Bill", "Billerson"));
        return list;
    }
}

Then the only option that will appear in the Website Data Sources pane is "GetNamesList" with the properties FirstName and LastName. Since your Linq-to-SQL generated classes have properties that are IQueryable, but not methods, you might want to add partial classes that have methods to expose these collections. So if you have a Products property, create a partial class with a signature of:

public IEnumerable GetAllProducts();

But I'm not sure that you can make the ReportViewer work with an existing LinqDataSource control. Instead, it basically does the same thing as the LinqDataSource: instantiates a class and calls the method you specify to get data.

Helpful Links: http://msdn.microsoft.com/en-us/library/ms251692(VS.80).aspx http://forums.asp.net/p/1430385/3667394.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜