LinqMetaData Parameterless Constructor

Posts   
1  /  2
 
    
tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 14-May-2008 04:44:20   

Hello Frans, I tried using the LinqMetaData with the latest beta build and when hooking it up to DevExpress's LinqServerModeDataSource, I get no errors, just no records... there are indeed records, just no showing...

I am guessing that is has something to do with the fact that the LinqMetaData needs an DataAccessAdapter in order to function... and my question, why can you not simply define your own DataAccessAdapter when there are none passed in... That would also make it more "Linq" like ...

How would you like me to proceed to determine the problem? THere are no exceptions, so I assume it is the parameterless constructor issue.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 14-May-2008 09:25:31   

YOu can add the adapter later, please see the .doc for details about that.

If they require an empty ctor, you then have to create a derived class from LinqMetaData (it's in the generated code) and in there add a parameterless ctor and simply call the base class' ctor by passing a new dataaccessadapter instance. But perhaps I'm not understanding your question correctly

Frans Bouma | Lead developer LLBLGen Pro
Isz
User
Posts: 108
Joined: 26-Jan-2006
# Posted on: 17-May-2008 00:38:15   

Does anyone have any example of wiring up the AspxGridView with LinqServerModeDataSource and LinqMetaData?

Perhaps a few snippets of code might help me get started.

Many thanks!

Isz

tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 17-May-2008 00:57:38   

Isz wrote:

Does anyone have any example of wiring up the AspxGridView with LinqServerModeDataSource and LinqMetaData?

Perhaps a few snippets of code might help me get started.

Many thanks!

Isz

It seems you have to handle the selecting event, and give the LinqMetaData instance an adapter... as stated here, the parameterless constructor does not open an adapter itself, so you cannot make it work out of the box. I have yet to get it to work, although I have done much to test other scenarios.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 17-May-2008 13:17:06   

Can't you assign the queryable in the PageLoad routine?

DataAccessAdapter adapter= new DataAccessAdapter(); var q = new LinqMetaData(adapter).Customers;

// bind q to source

Frans Bouma | Lead developer LLBLGen Pro
tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 17-May-2008 16:22:15   

Otis wrote:

Can't you assign the queryable in the PageLoad routine?

DataAccessAdapter adapter= new DataAccessAdapter(); var q = new LinqMetaData(adapter).Customers;

// bind q to source

That is pretty much the same as handling the selecting event, what benefit do you get handling this in the PageLoad?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 17-May-2008 17:17:56   

tzarger wrote:

Otis wrote:

Can't you assign the queryable in the PageLoad routine?

DataAccessAdapter adapter= new DataAccessAdapter(); var q = new LinqMetaData(adapter).Customers;

// bind q to source

That is pretty much the same as handling the selecting event, what benefit do you get handling this in the PageLoad?

I was under the assumption you grabbed the queryable in the select event, and then set the adapter in that queryable object, but if you do the same as above, it doesnt' matter of course where you place that code simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Isz
User
Posts: 108
Joined: 26-Jan-2006
# Posted on: 20-May-2008 23:49:40   

Hi tzarger...

Is this about what you had in your select?


        protected void LinqServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
        {
            var query = new LinqMetaData(DataAccessAdapterFactory.CreateStandardAdapter());
            e.QueryableSource = from u in query.User select u;
        }


I get no records as well, so I am not sure if you figured out how to do this yet. The above doesn't seem right anyway, as it seems the LinqServerModeDataSource should be generating the linq from its mapping to the data context (DataContextUser.dbml), then somehow feeding it to LLBLGen [confused confused ]

Also, there doesn't seem to be a way to do this in the Page_Load since LinqServerModeDataSource doesn't appear to expose an IQueryable property. The WinForms version does though.

Please advise if any progress has been made.

Hopefully this will all make sense soon... Very grateful!

isz

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 21-May-2008 10:29:11   

I don't see why you need a dbml file? After all, you're not using linq to sql. if this whole structure needs linq to sql to function properly, it's IMHO not really useful. (what if the db is oracle?)

Did you open a ticket at DevExpress? It seems a proper support call to them IMHO... I don't know the answer unfortunately...

Frans Bouma | Lead developer LLBLGen Pro
Isz
User
Posts: 108
Joined: 26-Jan-2006
# Posted on: 21-May-2008 16:07:08   

True... I don't see why it's needed either. If we get something to work, we'll post something somewhere in case others are trying to mashup these two technologies.

Thanks for the honest effort!

tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 21-May-2008 16:42:47   

Here is what I was doing, however this appears to bring back rows, because I get a "Specified Cast is not valid" error...


        protected void LinqServerModeDataSource1_Selecting( object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e )
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            e.KeyExpression = "ProductLinkID";
            e.QueryableSource = from pl in new LinqMetaData( new DataAccessAdapter() ).ProductLink select pl;
        }

If I leave out the e.KeyExpress, I get nothing back, and no error. So bottom line, I cannot get the LinqMetaData to work with the LinqServerModeDataSource.

PS, I don't use the DBML file.

tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 21-May-2008 16:53:50   

It kind of appears that the LinqMetaData is more of a method for using Linq with LLBGen entities, etc... does not fully act like a LinqDataContext, as too many properties seem to be browsable and show up in the grid..

I even tried this:


protected void LinqServerModeDataSource1_Selecting( object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e )
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            e.KeyExpression = "ProductLinkID";
            var q = from pl in new LinqMetaData( adapter ).ProductLink
                            select new { pl.ProductLinkID, pl.ProductID, pl.LinkTitle, pl.FileUrl };

            e.QueryableSource = q;
        }

and got "Object reference not set to an instance of an object. "

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 21-May-2008 17:21:19   

What's a LinqDataContext ? The linq to sql context? Yes, it's a different thing. Both produce IQueryable<T> objects, but the linq datacontext also can update stuff. I'm not sure if the webversion of devexpress' linqserver control assumes a linq to sql context...

The queryable should just be an IQueryable<T>, without reference to a linq to sql context, so I don't know what kind of errors you run into. If you get cast / other errors, a stack trace is the minimum we need to give pointers... also I think devexpress might have a hint or 2 where to look/how to hook it up...

Frans Bouma | Lead developer LLBLGen Pro
tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 21-May-2008 17:39:50   

Otis wrote:

What's a LinqDataContext ? The linq to sql context? Yes, it's a different thing. Both produce IQueryable<T> objects, but the linq datacontext also can update stuff. I'm not sure if the webversion of devexpress' linqserver control assumes a linq to sql context...

The queryable should just be an IQueryable<T>, without reference to a linq to sql context, so I don't know what kind of errors you run into. If you get cast / other errors, a stack trace is the minimum we need to give pointers... also I think devexpress might have a hint or 2 where to look/how to hook it up...

My bad I missed the space, yes, I meant a Linq DataContext.

Here is a stack trace, from it, it appears this is a DevExpress issue. I have successfully hooked up the LinqServerModeDataSource in the exact same way, however I used a Linq DataContext from a Linq to Sql project. So I am pretty sure this is a valid way to hook it up.

Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   DevExpress.Data.Linq.LinqServerModeWebFrontEndOwner.Crash(Exception e) +27
   DevExpress.Data.Linq.Helpers.LinqServerModeCache.CrashLanding(Exception e) +65
   DevExpress.Data.Linq.Helpers.LinqServerModeCache.CreateTopGroupInfo() +748
   DevExpress.Data.Linq.Helpers.LinqServerModeCache.get_TotalGroupInfo() +34
   DevExpress.Data.Linq.Helpers.LinqServerModeCache.Count() +25
   DevExpress.Data.Linq.Helpers.LinqServerModeWrapper.get_Count() +37
   DevExpress.Data.Linq.Helpers.LinqServerModeFrontEnd.get_Count() +35
   DevExpress.Data.Helpers.BaseDataControllerHelper.get_Count() +48
   DevExpress.Data.DataControllerBase.get_ListSourceRowCount() +52
   DevExpress.Data.DataController.get_VisibleListSourceRowCount() +28
   DevExpress.Data.DataController.get_VisibleCount() +78
   DevExpress.Data.DataController.DoRefresh(Boolean useRowsKeeper) +70
   DevExpress.Data.DataControllerBase.DoRefresh() +28
   DevExpress.Data.DataController.EndUpdateCore(Boolean sortUpdate) +80
   DevExpress.Data.DataControllerBase.EndUpdate() +25
   DevExpress.Data.DataControllerBase.OnListSourceChanged() +152
   DevExpress.Data.DataControllerBase.SetListSourceCore(IList value) +74
   DevExpress.Data.DataControllerBase.SetListSource(IList value) +47
   DevExpress.Data.BaseListSourceDataController.SetDataSource(Object dataSource) +62
   DevExpress.Web.Data.WebDataControllerProvider.CreateDataController(Object dataSource) +382
   DevExpress.Web.Data.WebDataControllerProvider.SetDataSource(Object dataSource) +28
   DevExpress.Web.Data.WebDataProxy.SetDataSource(Object dataSource) +98
   DevExpress.Web.ASPxGridView.ASPxGridView.PerformDataBinding(String dataHelperName, IEnumerable data) +75
   DevExpress.Web.ASPxClasses.Internal.DataHelper.PerformDataBinding(IEnumerable data) +52
   DevExpress.Web.ASPxClasses.Internal.DataHelper.OnDataSourceViewSelectCallback(IEnumerable data) +65
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +29
   DevExpress.Web.ASPxClasses.Internal.DataHelper.PerformSelect() +146
   DevExpress.Web.ASPxGridView.GridViewDataHelper.PerformSelect() +109
   DevExpress.Web.ASPxClasses.Internal.DataContainer.PerformSelect() +117
   DevExpress.Web.ASPxClasses.ASPxDataWebControlBase.DataBindCore() +36
   DevExpress.Web.ASPxClasses.ASPxDataWebControlBase.DataBind() +143
   DevExpress.Web.ASPxClasses.Internal.DataHelperBase.EnsureDataBound(Boolean ensureChildControls) +106
   DevExpress.Web.ASPxClasses.Internal.DataHelperBase.EnsureDataBound() +29
   DevExpress.Web.ASPxClasses.Internal.DataContainer.EnsureDataBound() +120
   DevExpress.Web.ASPxClasses.ASPxDataWebControlBase.OnPreRender(EventArgs e) +39
   System.Web.UI.Control.PreRenderRecursiveInternal() +86
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

here is my HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="testapp.com.WebForm1" %>

<%@ Register assembly="SD.LLBLGen.Pro.ORMSupportClasses.NET20" namespace="SD.LLBLGen.Pro.ORMSupportClasses" tagprefix="llblgenpro" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <dxwgv:aspxgridview id="ASPxGridView1" runat="server" autogeneratecolumns="False" datasourceid="LinqServerModeDataSource1" keyfieldname="ProductLinkID">
                <columns>
                    <dxwgv:gridviewdatatextcolumn fieldname="ProductID" visibleindex="0"></dxwgv:gridviewdatatextcolumn>
                    <dxwgv:gridviewdatatextcolumn fieldname="LinkTitle" visibleindex="1"></dxwgv:gridviewdatatextcolumn>
                    <dxwgv:gridviewdatatextcolumn fieldname="FileUrl" visibleindex="2"></dxwgv:gridviewdatatextcolumn>
                </columns>
            </dxwgv:aspxgridview>
            <dxdtlnq:linqservermodedatasource id="LinqServerModeDataSource1" runat="server" contexttypename="testapp.Data.Linq.LinqMetaData" onselecting="LinqServerModeDataSource1_Selecting" tablename="ProductLink" />
    </form>
</body>
</html>

here is the code behind:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using testapp.Data.Linq;
using testapp.Data.DatabaseSpecific;

namespace testapp.com
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load( object sender, EventArgs e )
        {

        }

        protected void LinqServerModeDataSource1_Selecting( object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e )
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            e.KeyExpression = "ProductLinkID";
            var q = from pl in new LinqMetaData( adapter ).ProductLink
                            select new { pl.ProductLinkID, pl.ProductID, pl.LinkTitle, pl.FileUrl };

            e.QueryableSource = q;
        }
    }
}

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 21-May-2008 19:28:03   

That looks like a devexpress crash.

Could you take this up with DevExpress to see if there's a bug somewhere and who has to fix what? Your stacktrace shows that the nullref is inside their code, it doesn't have to mean it's due to their code, but I think they're more able to debug this at that level than we do (as we can't break at that point)

Frans Bouma | Lead developer LLBLGen Pro
tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 21-May-2008 19:37:10   

Otis wrote:

That looks like a devexpress crash.

Could you take this up with DevExpress to see if there's a bug somewhere and who has to fix what? Your stacktrace shows that the nullref is inside their code, it doesn't have to mean it's due to their code, but I think they're more able to debug this at that level than we do (as we can't break at that point)

Yes, from the stack trace, I would agree. I will enter a ticket... although, I am afraid to do so. confused

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 21-May-2008 20:54:54   

tzarger wrote:

Otis wrote:

That looks like a devexpress crash.

Could you take this up with DevExpress to see if there's a bug somewhere and who has to fix what? Your stacktrace shows that the nullref is inside their code, it doesn't have to mean it's due to their code, but I think they're more able to debug this at that level than we do (as we can't break at that point)

Yes, from the stack trace, I would agree. I will enter a ticket... although, I am afraid to do so. confused

Why would you be afraid? simple_smile You're a paying customer, you and them are professionals, I don't think they'll bite you wink . A vendor in general might not be pleased that a bug is present in the code, but at the same time a vendor will be very happy that the bug is reported so it can be fixed.

Frans Bouma | Lead developer LLBLGen Pro
tzarger
User
Posts: 87
Joined: 14-Jun-2007
# Posted on: 21-May-2008 21:02:08   

Otis wrote:

Why would you be afraid? simple_smile You're a paying customer, you and them are professionals, I don't think they'll bite you wink . A vendor in general might not be pleased that a bug is present in the code, but at the same time a vendor will be very happy that the bug is reported so it can be fixed.

Well, I opened the ticket about the Paging parameters and then it seemed like that spiraled a bit out of control, and do not want to go there again. They will think I am a problem child, being so persistent that there stuff doesn't work... in certain circumstances of course... flushed

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 21-May-2008 21:21:11   

tzarger wrote:

Otis wrote:

Why would you be afraid? simple_smile You're a paying customer, you and them are professionals, I don't think they'll bite you wink . A vendor in general might not be pleased that a bug is present in the code, but at the same time a vendor will be very happy that the bug is reported so it can be fixed.

Well, I opened the ticket about the Paging parameters and then it seemed like that spiraled a bit out of control, and do not want to go there again. They will think I am a problem child, being so persistent that there stuff doesn't work... in certain circumstances of course... flushed

Heh, naa, don't worry. We too caused a bit of uproar in that paging stuff, as we simply wanted the control vendor to make things work so WE don't have to explain time and time again to customers that things don't work but it's not our fault. Just open the ticket, I'm sure they're willing to help. It's also possible that their code crashes because our query returned to the grid is bad, in case we have to fix something, but unless we know what happens inside the grid, we can't know what's wrong there.

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 22-May-2008 21:24:20   

The DataAccessAdapter and LinqMetaData are probably out of scope at the moment the query is executed. Create fields for both and instantiate them in Page_Load and dispose them in Page_Unload.

HTH

Isz
User
Posts: 108
Joined: 26-Jan-2006
# Posted on: 23-May-2008 20:01:02   

The DataAccessAdapter and LinqMetaData are probably out of scope at the moment the query is executed. Create fields for both and instantiate them in Page_Load and dispose them in Page_Unload.

I gave that a shot, didn't work for me.

I posted a ticket + project at http://devexpress.com/Support/Center/p/Q104692.aspx

Perhaps $$$ will help motivate a solution.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 24-May-2008 11:07:21   

DevExpress has mailed me last week to test a new build of the grid with the new paging flag. I'll do that on monday morning. I'll also take a shot at your problem to see if I can get the linq source to work.

twaindev wrote:

The DataAccessAdapter and LinqMetaData are probably out of scope at the moment the query is executed. Create fields for both and instantiate them in Page_Load and dispose them in Page_Unload.

HTH

That's not important, because the queryable contains a reference to the provider, which contains a reference to the adapter simple_smile The linqmetadata is just there to produce the queryable.

Frans Bouma | Lead developer LLBLGen Pro
twaindev avatar
twaindev
User
Posts: 178
Joined: 08-Oct-2007
# Posted on: 24-May-2008 20:24:36   

Otis wrote:

That's not important, because the queryable contains a reference to the provider, which contains a reference to the adapter simple_smile The linqmetadata is just there to produce the queryable.

Well I also thought this when I started testing Linq To Sql with an ASP.NET ListView, but I had to define a field to instantiate the DataContext, otherwise I got the same NullReferenceExceptions. This was during the beta of Linq To Sql. I did not test this with the RTM. I will have to find some time to do that and also test it with Linq To LLBLGen, but first I'm off to France for a two week vacation sunglasses

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 25-May-2008 11:54:05   

Hmm. If you need a context, it's pretty locked down to linq to sql, or do they also accept an Entity framework context? Dynamic Data also worked this way, but they now have it made optional, so it's no longer a burden that you don't use linq to sql.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 26-May-2008 18:55:40   

Isz wrote:

The DataAccessAdapter and LinqMetaData are probably out of scope at the moment the query is executed. Create fields for both and instantiate them in Page_Load and dispose them in Page_Unload.

I gave that a shot, didn't work for me.

I posted a ticket + project at http://devexpress.com/Support/Center/p/Q104692.aspx

Perhaps $$$ will help motivate a solution.

They call the provider's Execute directly, which causes the provider to bypass a final conversion routine for scalars. Linq normally doesn't call that execute directly.

I'll see if I can fix this.

var q = from c in metaData.Customer select c; int count = q.Count(); works as expected, the expression tree is also exactly the same.

The problem is that the query itself, onto which Count is called, is a list, and the count is just a single value query, but still stored in a list (with 1 value) as it otherwise would require a different projection code path, which is silly.

(edit). I've fixed it. Fixed in next build. (hopefully tomorrow (tuesday)).

Frans Bouma | Lead developer LLBLGen Pro
1  /  2