Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
LinqServerModeDataSourceMain Selecting Event
Message
From
07/06/2017 16:11:22
 
 
To
07/06/2017 14:56:45
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 4.0
Database:
MS SQL Server
Miscellaneous
Thread ID:
01651838
Message ID:
01651840
Views:
104
>Hi,
>
>I am trying something new: using LINQ to try to filter data in an ASPXGridView (DevExpress).
>
>The grid's source data is defined like this:
>
>
<cc1:LinqServerModeDataSource ID="LinqServerModeDataSourceMain" runat="server" 
>                        ContextTypeName="RESREPRICER.Web.DataClassesTransactionsDataContext" 
>                        TableName="viewTransactions" 
>                        OnSelecting="LinqServerModeDataSourceMain_Selecting"/>
>
>I need to filter that data based on a session variable so that whoever is logged in can see only their own data. Note that if the user logged in is an administrator, they should be able to see all data.
>
>This is the code I am trying to write (I've copied the SQL code from SSMS and rearranged it to fit the LINQ way):
>
>
>        protected void LinqServerModeDataSourceMain_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
>        {
>            //DataClassesDataContext db = new DataClassesDataContext();
>            RESREPRICER.Web.DataClassesTransactionsDataContext db = new DataClassesTransactionsDataContext();
>            string OfficeID = (String)Session["OID"];
>            var data = (from viewTransactions in db.viewTransactions
>                        where viewTransactions.OID == OfficeID
>                        select GUID, DateImported, OID, PNR, StoredFare, RMQ, LowerFare, (StoredFare - LowerFare) * ISNULL(Passengers, 1) AS FareDiff, Timestamp, DATENAME(Month, Timestamp) AS DatedMonth, 
>                      DATEPART(yyyy, Timestamp) AS DatedYear, DATENAME(quarter, Timestamp) AS DatedQuarter, DATENAME(Day, Timestamp) AS DatedDay, DATENAME(weekday, 
>                      Timestamp) AS DatedWeekday, REPLACE(CONVERT(CHAR(5), Timestamp, 108), ':', '') AS DatedTime, MFRA, ScriptResult, AgentID, PNRStatus, Segments, Currency
>					  ,Passengers);
>            e.QueryableSource = data;
>        }
>
>
>I am getting these errors (ignoring the other errors that are due to my SQL syntax):
>On the var: Error Implicitly-typed local variables cannot have multiple declarators
>on the GUID: Error The name 'GUID' does not exist in the current context (GUID is a field in the view)
>
>Can anyone help me through this?

I believe I have it solved:
        protected void LinqServerModeDataSourceMain_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
        {
            //DataClassesDataContext db = new DataClassesDataContext();
            RESREPRICER.Web.DataClassesTransactionsDataContext db = new DataClassesTransactionsDataContext();
            string OfficeID = (String)Session["OID"];

            e.KeyExpression = "GUID";
            e.QueryableSource = from viewTransaction in db.viewTransactions
                                where viewTransaction.OID == OfficeID
                                select new { viewTransaction.GUID, 
                                             viewTransaction.DateImported, 
                                             viewTransaction.OID, 
                                             viewTransaction.PNR, 
                                             viewTransaction.StoredFare, 
                                             viewTransaction.RMQ, 
                                             viewTransaction.LowerFare,
                                             viewTransaction.FareDiff, 
                                             viewTransaction.Timestamp,
                                             viewTransaction.DatedMonth,
                                             viewTransaction.DatedYear,
                                             viewTransaction.DatedQuarter,
                                             viewTransaction.DatedDay,
                                             viewTransaction.DatedWeekday,
                                             viewTransaction.DatedTime,
                                             viewTransaction.MFRA,
                                             viewTransaction.ScriptResult,
                                             viewTransaction.AgentID,
                                             viewTransaction.PNRStatus,
                                             viewTransaction.Segments,
                                             viewTransaction.Currency,
                                             viewTransaction.Passengers
                                };
        }
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Reply
Map
View

Click here to load this message in the networking platform