Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
LinqServerModeDataSourceMain Selecting Event
Message
De
07/06/2017 14:56:45
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Titre:
LinqServerModeDataSourceMain Selecting Event
Versions des environnements
Environment:
C# 4.0
Database:
MS SQL Server
Divers
Thread ID:
01651838
Message ID:
01651838
Vues:
46
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?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform