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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Is there a way to query entity based on multiple filter criteria? WCF Data Services, Linq to Entiti

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :WCF

Instead of:

DW_CMSOPEN dwc = new DW_CMSOPEN(new Uri("http://acctdev02/WCFDataService/EmployeeService.svc"));

dwc.Credentials = System.Net.CredentialCache.DefaultCredentials;

var employees = from emp in dwc.Employees 
             where emp.DEPT == "123"
             select emp;

I'd like the linq query to resemble:

var employees = from emp in dwc.Employees
              where emp.DEPT // in {"123", "456", etc}
              select emp;

View Complete Post

More Related Resource Links

Data Points: LINQ Projection Queries and Alternatives in WCF Services


LINQ's ability to project randomly shaped data into anonymous types can be a blessing and a source of frustration, says Julie Lerman. It's great when you just need to grab a special view of your data, but it can be problematic in certain circumstances. She explains what the limitations are and how to get around them.

Julie Lerman

MSDN Magazine May 2010

VS 2010: Entity Framework 4.0 and WCF Data Services 4.0 in Visual Studio 2010


Elisa Flasko takes you through a sample weblog application to demonstrate how new improvements in Entity Framework and WCF Data Services work together to simplify the way data is modeled, consumed and produced in Visual Studio 2010.

Elisa Flasko

MSDN Magazine April 2010

SOA Data Access: Flexible Data Access With LINQ To SQL And The Entity Framework


Building a data access layer using LINQ to SQL and the ADO.NET Entity Framework allows you to decouple your application from the persistence technology you're using.

Anthony Sneed

MSDN Magazine December 2008

Data Points: Standard Query Operators with LINQ


LINQ to Objects and LINQ to Entities have an arsenal of Standard Query Operators that operate on sequences to perform a wide variety of operations.

John Papa

MSDN Magazine March 2008

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

How to query for id's of the fields with List Data Retrival Services Query() web service

Since i marked a post as answer in my previous topic, it seems that people dont visit the topic anymore as they see it as "answered" while it actually is only partially answered. So i guess i have to ask again in a different topic.    I need to get data from Sharepoint Server (3.0 i belive) for my Integration Services project. For that i use Sharepoint's webservices. I've read tutorials and downloaded sample programs to talk to WSS web services. I realise i have two ways to get items in a list: Use Query() or GetListItems(). Problem is, GetListItems() has a mandatory "Row limit" field and i might have to import ALOT of fields, so i thought Query() is better for me.  But, when using GetListItems(), the WSS returns the ID of the fields (for example, for a field of type user, something like "395;Ivanov Ivan Ivanovich" is returned) but when using Query() for the same list, WSS returns only the field value ("Ivanov Ivan Ivanovich") without the ID. I need it to return the ID as well. How can i set it up, on my side or server side, so i would receive the ID's, not only the values of the fields that are actually linking to something by ID when i use Query() web service?     

How to filter managed meta data column using page query string?

I have two managed term sets as follows: Articles:Downloads Projects:Downloads I am trying to use a content query web part to filter a list based on the above manged meta data column. I want to filter out only "Articles:Downloads" Scenario 1: When I edit the web part and directly set the filter option with the managed meta data column to "Articles:Downloads" it works fine. When I export the web part, in the .webpart file, the "FilterValue1" property has a value "Downloads|9096e43b-555d-4879-9acc-b4ada9ea9910". Scenario 2: I want the web part to get the filter information from query string [PageQueryString:pageType]. So I tried using these options: a) pageType=Downloads      This works but returns downloads under 'projects' as well. (i want downloads only under 'articles')  b) pageType=Articles:Downloads     Does not work and shows no records c) pageType = Downloads|9096e43b-555d-4879-9acc-b4ada9ea9910     Does not work. (This value is the same as one found in 'FilterValue1' of the static web part). c) pageType = Articles:Downloads|9096e43b-555d-4879-9acc-b4ada9ea9910     Does not work. d) pageType = 9096e43b-555d-4879-9acc-b4ada9ea9910     Does not work.   What am I missing here? Can some one please help?

How to setup Query Result Shaping for LinQ to SQL instead of Entity Framework?

Hi, I am new to this, and I am trying to implement a linq query similar to db.Genres.Include("Albums") command from mvc music store using my current DB setup. I realize that the tutorial mentions Checlking the "Include foreign key columns in the method" when creating the tables in ADO.NET, but if I am using LINQ to SQL classes, then how can I obtain the same effect. And how do I use db.Genres.Include("Albums") to simplify my life? Thanks

CAML query to access List data across multiple site collection.

Hi   Is there any way to get the Task List data across multiple site collection using CAML query. Currently, I have the code which will retrieve the data from a single site collection. Below is the code.                           /***************************************************I am using Moss2007.Thanks!Ravi             SPSiteDataQuery q = new SPSiteDataQuery();             q.ViewFields = "<FieldRef Name=\"Title\" />" "<FieldRef Name=\"Status\" Nullable=\"TRUE\"/>";             q.Lists = "<Lists ServerTemplate=\"107\"/>";             q.Webs = "<Webs Scope=\"SiteCollection\"/>";             q.Query = "<Where>" +                                "<Eq>" +                                     "<FieldRef Name=\"Status\" />" + "<Value Type=\"Choice\">Not  Started</Value>" +                                     "</Eq>" +                         "</Where>";             DataTable dt=null;             using (SPSite s = new SPSite("http://banglabguest1:31000/"))             {                 SPWeb w = s.OpenWeb();                 dt = w.GetSiteData(q);                 w = null;             }                              *************************

delete node based on criteria - linq to xml


I'm trying to delete an element based on its inner text but seem to not quite have it...

I have an xml doc like this:
<department name="Claims">
    <MyElement>Big Test</MyElement>


My linq to xml is:

XDocument ldoc = XDocument.Load(Server.MapPath("/XML/Settings.xml"));

doc.Elements("department").Where(s => s.Element("keywords").Value == "phone").Remove();



When I click my link button the element <keywords>phone</keywords> is never deleted.

Any idea what i'm doing wrong?




LINQ to Entity - using join for multiple table


I have my SQL query which needs to be conerted to Linq to Entity,

select pfr_sa.SID,pfr_sa.SourceGroupID,tx.txroll_cadaccountnumber,tx.txroll_StreetNumb

Using LINQ to XML to query XML data


Hello I have this xml document that I want to query using linq to load to c# object. I must be able to search a chapter displaying all line in the chapter or search a specific line using index in this example I'm trying to search a chapter with all the lines on it and the output show chapter with the first line only. And it does the same thing when I want to show everything from my xml it shows each chapter with the first line only. could any one provide me with necessary code to achieve this

<?xml version="1.0" encoding="utf-8" ?>
  <chapter index="1" name="Get Started">
      <line index="1" text="After using this software you will be able to pronounce arabic words"/>
      <line index="2" text="You will be able to read and write arabic words"/>
      <line index="3" text="The first lesson will show you each arabic alphabets"/>
  <chapter index="2" name="Basics">
      <line index="1" text="The next example takes the concept further by filtering data"/>

How use sum in Entity Data Model with linq?



i have a database with 4 table aspnet_Users, Forum, Topic, Post thay are related:

aspnet_Users with Topic by UserId

Forum with Topic by ForumId

Topic with Post by TopicId

i created a linq to get data from Database like:

Dim db As New MelorinEntities()
        Dim Topics = From t In db.Topic _
                     Join u In db.aspnet_Users _
                     On t.UserId Equals u.UserId _
                     Where t.ForumId = _ForumId _
                     Select t.UserId, t.TopicId, t.Name, t.IsLock, t.NumberOfView, _


 now i need to get also how meny post are in a topic but i don't know how to write the querry

can you please help me?



WCF - Entity Framework - POCO - Caching with multiple services



We have an architecture where we use Entity Framework with POCO, and the code-first approach (no edmx file). In order to explain the problem I have to explain a little bit about our architecture:

We have one layer which contains Routing Services (for load balancing and security), and a layer of Data Access Services. All services are hosted in IIS.

What we would like is to have caching of our (Entity Framework) Context, so we made the context static, and thought it would be shared between the different services. Well, it's not... 

The scenario (where we noticed the problem) was that we did some changes to an transaction through the Transaction services. We then did a search through the Search services, and found that the data wasn't updated. Well, actually the data are updated, and saved to the DB, it's just that the "Search Context" is out of sync. When retrieving the data from the Transaction service, we got the correct data, as expected.

So, after hours of googling I still haven't found a solution to the problem, and I'm hoping to get some response here.

Master Data Services, SSRS, and the Query Designer.


Hey everyone,


For the most part, I have this thing figured out; however, I now need to assign to a property of a method's parameter a collection of member types.


Here is my query (I have emboldened the segment of the query which my question is directed towards):


          <Method Namespace="http://schemas.microsoft.com/sqlserver/masterdataservices/2009/09" Name="MetadataGetRequest">


          <Parameter Name="ResultOptions" Type="XML">





 <Parameter Name="SearchCriteria" Type="XML">


<MemberTypes attr0="MemberTypeArra

data shaping question - can this much conditional processing can be done within the linq query?



I have a scenario where I need to map the value of a field to a different value... easier explained with simple example:

when actual field data is "RED" I need to return "some other data"
when actual field data is "BLUE" I need to return "something else" 

so I've written linq to sql statements that project and shape, but I've never had to include any 'conditional' processing, can you?

Entity Framework - How to Query Based on Relationships


I have the following related tables:











User (FK - Users: Id)

Status (FK - UserStatuses: Id)


As you can see, UserStatuses is a reference table with various statuses. Users_UserStatus is a join table between Users and UserStatuses. Using Entity Framework, how can I do a conditional to check if the latest StatusDate is "Pending"? As of now, I have the following:

            Dim user As User = rep.Users.FirstOrDefault(Function(x) x.Username = userName)
            If user Is Nothing Then
                Return False
                Dim hashedPassword As String = Helpers.Security.CreatePasswordHash(password, user.PasswordSalt)
                If hashedPassword = user.Password Then
                    Return True
                    Return False
                End If
            End If


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