.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Imran Ghani
Post New Web Links

Problem with Where in LINQ

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :ASP.Net
 

Hi

How can i use this
Select
Where IsEnabled Is 1 _

In this code

MyRep.DataSource = Q

MyRep.DataBind()Public Sub linqdb()Dim DBconn As New


View Complete Post


More Related Resource Links

LINQ query with multiple joins, problem

  

I am using a LINQ query with multiple joins, the last join does not return any values even though values exist in the database. Below is my code.

when the query returns suiteNameTrg and SuiteTypeTrg are empty, all other values are returned correctly.

string suiteNameTrg = string.Empty;
            string suiteTypeTrg = string.Empty;
            using (DataClassesDataContext db = new DataClassesDataContext())
            {  
                    var productQuery = from assets in db.ASSETs
                    join relocatableUnits in db.RELOCATABLE_UNITs on assets.RUID equals relocatableUnits.RUID into assets_units
                    from relocatableUnits in assets_units.DefaultIfEmpty()
                   join build in db.BUILDINGs on assets.BUILDING_ID equals build.BUILDING_ID into assets_bins
                   from build in assets_bins.DefaultIfEmpty()
                   join test in db.TEST_SUITEs on assets.TEST_SUITE_ID equals test.TEST_SUITE_ID into test_bins
                   from test in test_bins.DefaultIfEmpty()
                    
                    join testTrgt in db.TEST_SUITEs on assets.TARGET_TEST_SUITE_ID equals testTrgt.TEST_SUITE_ID into testTrgt_bins
                    from testTrgt in testTrgt_bins.DefaultIfEmpty()

                    select new
                                   {
                          

Problem updating records with LINQ, Concurrency?

  
 My project includes a grid view with some updtable fields, some fields throw an error on update and some do not and it does not really make sense. WORK_STATION_ID does not cause an error, ROOM _ID cause an error, both are int? (I am using c#) and for update I use the code liste below.using (DataClassesDataContext db = new DataClassesDataContext()) { var product = (from p in db.ASSETs where p.ASSET_ID == ASSET_ID select p).Single(); product.WORK_STATION_ID=WORK_STATION_ID; product.ROOM_ID=ROOM_ID; db.SubmitChanges(); }    Row not found or changed. 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.Data.Linq.ChangeConflictException: Row not found or changed. Source Error: Line 93: Line 94: Line 95: db.SubmitChanges(); Line 96: Line 97: Source File: C:\Projects\TEST_II\trunk\ObjectDataSourceLibrary\AssetController.cs Line: 95 Stack Trace: [ChangeConflictException: Row not found or changed.] System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) +963417 Syst

Problem while retrieving data from a lookup column from sharepoint linq.

  
Hi I am working with sharepoint linq concept. When I am giving a query with lookup column It's working fine.  But when i am trying to retrieve the data from a look up column to spgridview. I was unable to get the output. Here is the above code which i have worked.   string strTitle = string.Empty; string strStatus=string.Empty; var context = new LinqSampleDataContext(SPContext.Current.Web.Url); EntityList<SharePoint2010ConceptsItem> Concept = context.GetList<SharePoint2010ConceptsItem>("SharePoint 2010 Concepts"); var query = from cs in Concept where cs.Status.Title.ToString()!="Completed" select new { cs.Title, cs.Id, //cs.Status }; sgvConcepts.DataSource =query; sgvConcepts.DataBind();   Any help me plz how to retrieve the data from a lockup column.bvnprasad

Problem with Retrieving data from lookup column using SharePoint 2010 Linq Concept

  
Hi I am working with sharepoint linq concept. When I am giving a query with lookup column It's working fine.  But when i am trying to retrieve the data from a look up column to spgridview. I was unable to get the output. Here is the above code which i have worked.   string strTitle = string.Empty; string strStatus=string.Empty; var context = new LinqSampleDataContext(SPContext.Current.Web.Url); EntityList<SharePoint2010ConceptsItem> Concept = context.GetList<SharePoint2010ConceptsItem>("SharePoint 2010 Concepts"); var query = from cs in Concept where cs.Status.Title.ToString()!="Completed" select new { cs.Title, cs.Id, //cs.Status }; sgvConcepts.DataSource =query; sgvConcepts.DataBind();   Any help me plz how to retrieve the data from a lockup column.bvnprasad

Linq to SQL Web Service cannot be serialized problem

  
Hello All, Ok so I'm playing around with Web Services using Linq to SQl. I apparently have  a lot of learning to do. What I'm trying to do below is pull data from the Northwind db Employee Table. I don't need to see the whole table, I'm just trying to select individual(s) but I keep getting the following error  "System.Data.Linq.Binary cannot be serialized because it does not have a parameterless constructor" Code Below: Thanks in advance for any advice <WebMethod()> _ Public Function EmployeeInfo() As List(Of Employee) Dim db As New NorthwindDataContext() Dim output = From cust In db.Employees _ Select cust.EmployeeID, cust.FirstName, cust.LastName Return output End Function  

Linq to SQL - Association Property Name problem

  
Is it possible to specifiy a custom property name for a foreign key association in Linq to Sql? For example, if you have an "Order" class that has a "Customer" EntityRef, that's fine.  But what if instead of myOrder.Customer you wanted the property name to be myOrder.PreferredCustomer.sqlmetal and the designer are both always using the table name as the Property name.  So myOrder.Customer is the only option I have, other than hacking through the generated file.You can change the storage option of the association attribute, but that pertains to the underlying member, NOT the public property.Thanks.

LINQ: Problem in fetching data

  
Hi, i am developing something in LINQ, in this i am using some query for selecting data like this:var data = (from w in db2.TextSubCats where w.SubCatName.Trim()==reci_i.Recipe_cat.Trim() select w.SubCatName);but how could i fetch this data, i knows there is a solution by using foreach statement like this:foreach (var data_i in data){}my problem is this, if there no data returned by query then this foreach statment is just skipped.....so how could i get data returned by query in string so that i could perform my string manipulations... Thanks for your time.

Custom Webpart not working on "My Profile" page but works on all other pages. Linq Problem?

  
Hi, I created a publication site and in that site i created pages with specifique metadata (using a pagelayout with a custom content type)0. My webpart is getting data from those pages and displaying it. My webpart works on every page except on the "my profile" page(overview tab). I get the following error: Invalid Url: /TestSites/course I used the SPMETAL to create a class and i'm using this class to retrieve the data from the pages (with linq). The url i give to the entity is http://pcp/TestSites/course  this works fine on every site except on the my profile page. Can anybody help me? Here is the code i use to retrieve my data: EntitiesDataContext ctx = new EntitiesDataContext(courseSite); //Code below gets only the pages with a courses contentType. //EXCEPTION TRIGGERT ON THE FOLLOWING LINE IF IN PROFILE PAGE EntityList<Courses> course = ctx.GetList<Courses>("Pages"); //Writing the query to get the correct pages(with the course page layout only! var Query = from myCourse in course.ToList() where myCourse.CourseParticipants.Contains(myWeb.CurrentUser.LoginName) Select new{myTitle = myCourse.CourseTitle, myCompany = myCourse.Company, myPath = myCourse.Path, myName = myCourse.Name }; Thx.    

a problem with Linq to Entities

  

hi

i have a query that get some data from database and i want to databind a drop down list control that have alredy an item in it

the code is:

Private Sub DatabindFamilyMembers()

        Dim db As New AghakhanianEntities()
        Dim members = From m In db.UserProfiles _
                     Where m.IsFamilyMember = True _
                     Select FullName = m.FirstName + m.MiddleName + m.LastName, m.ProfileID _
                     Order By FullName

        Dim i As Integer = 0
        Dim text As String
        Dim value As String
        Do While i <= members.Count()
            value = members(i).ProfileID
            text = CType(members(i).FullName, String)
            i = i + 1
            ddlParent.Items.Insert(i, New ListItem(text, value))

        Loop

        ddlParent.DataBind()
    End Sub


when i run it in line value=.... get some error like:

LINQ to Entities does not recognize the method 'VB$AnonymousType_2`2[System.String,System.Int32] ElementAtOrDefault[VB$AnonymousType_2`2](System.Linq.IQueryable`1[VB$AnonymousType_2`2[System.String,System.Int32]], Int32)' method, and this method cannot be translated into a store expression.

Problem with adding custom propety to a data class using Linq.

  

Hello,

I tried to add a custom property to the data model:


public partial class Department
    {
        public string ExtensionIdName
        {
            get
            {
                return Extension.ExtensionName;
            }
            set
            {
            }
        }
    }

It seems that it works, but when I bind the data to a ListView it shows all the properties except the property I added manualy (ExtensionIdName).

Am I missing something or is there something wrong?


Dynamic LINQ Where problem

  

Guys

I am using LINQ TO ENTITIES.

I stumbled upon a problem while using Dynamic LINQ which is provided by Scott Guthrie. Basically I need a functionality where the user would be able to search by anything while on a gridview. Now the issue is that when the field to be searched is a string it works without problems, when it is an interger it is giving me a {"Operator '=' incompatible with operand types 'Int32?' and 'String'"}. Now the issue is that I would not be able to know what datatype the field is. If I convert the data to an INT it works without problems, but as I said I cannot since I would not be able to know beforehand the database data type. The place where it is giving me the error is shown in bold.

 

The second issue is that I have a CONTAINS functionality where the user would be able to type in anything and the system will create a CONTAINS linq statement to search for data. For one field it works without problems, while for another field the CONTAINS does not work and it gives me an OBJECT NOT SET TO AN INSTANCE when I try to access the list.  The code is shown underneath. I am using MVC and jqGrid.

private static string BuildWhereClause(JQGridRequest.SearchOperatorOptions SearchOperator, string FieldName)

{

 

swit

Linq problem C#

  

So I am trying to write the following SQL statment

 

SELECT InventoryItems.ItemID, Sum(IIf([hold]=-1,0,[Units])) AS SumInstock, Sum(IIf([hold]=-1,[Units],0)) AS SumHold

FROM InventoryItems

GROUP BY InventoryItems.ItemID;

 

this is what i have so far but not correct

 

Returnitems = user.GetAccessibleWarehouses()

.SelectMany(x => x.inventoryitem)

.Where(x => x.Active == true && x.Hold == false)

.Sum(x => x.Units);

 

Can anyone help me


Linq to XML Strange Problem

  

Guys,

I have a complex XML file to be parsed. So, I decided to do that using Linq to XML. I have no doubts that I did the best choice, but I'm fighting against a stranger problem: I can read all descendents nodes inside an Element, except one.

See the XML example below and I will explain that better, so you will be able to help me:

<det nItem="1">
      <prod>
            <cProd>135508</cProd> 
            <cEAN /> 
            <xProd>SOFTWARE </xProd> 
            <NCM>00000000</NCM> 
            <CFOP>5102</CFOP> 
            <uCom>UND</uCom> 
            </prod>
      <imposto>
            <ICMS>
                  <ICMS40>
                        <orig>1</orig> 
                        <CST>41</CST> 
                  </ICMS40>
            </ICMS>
      </imposto>
      <infAdProd>-ISENTO DE ICMS </infAdProd> 
</det>

Considerations:
1. Inside the XML file, there are a lot of <det nitem="n">
2. Problem: Using the ASP.NET code bellow I'm able to parse (read) everything above, except the <infAdProd> node.

 

Dim xmlFile As XDocument = XDocument.Load(LocalXMLPath)
Dim xmlFilePRO

Playing with Linq grouping: GroupByMany?

  
One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

  
I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

  
101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

Linq: how to share parameters between lambda expressions ?

  
When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend