ADO.NET :: LINQ - Exclude From A List Objects That Not Satisfying A Condition
Feb 16, 2011
I'm new on LINQ and I'm searching the best way to do this:
I have an object client that has a list of subscriptions. Subcription has a boolean attribute "Active". Now I want load only the clients with list > 0 and subscription active.
The question is: If a client has 3 subscriptions, but only 2 are active, how can I load only the latters ? I tried in this way:
[Code]....
The query selects clients that has at least one subscription active, but viewing the results, it loads also subscriptions not active of the same client.
I am using Linq To Sql to get List of objects with data from database. To bind data with a grid view i am creating a dataset explicitly and then adding List values to that explicitly created dataset.
Now my question is whether it is a good pratice to do what i am doing (in terms of resource utilization) or is there any better way to this...
have some Objects, lets say Employee and Role defined as below and I have defined relationships in my database that gives me a list of objects say employees and thanks to my framework each employee object also has a Role object linked via the RoleIDID, UserName, Password, Email, RoleIDRoleID, RoleNameSo in code I can do something like this
I know how to bind a simple objects to a dropdown list. However I am having problems binding my objects which contains sub objects to the control.i.e. with simple object i just do ddl.DataValueField = "myproperty" with my objects they contains sub objects which i want to bind. I have tried ddl.DataValueField = "sub-object.myproperty" which doesnt work.
string strCondition = "FirstName=='abc'" from p in People.Where(strCondition) select p
In our architecture we are usign both Linq-Sql as well Linq-Entity. So please give some thoughts wehter it is possible or not and is there any way to perform this?
I have a drop down that lists all our 40+ locations.. I then have a list box with all our locations as well. The client is presented with the question which locations have you worked at before. If they pick say 3 locations, i need to remove or disable those 3 from the drop down. I have other code for creating a drop down, but not sure where to go with this.
I have a list of customer Id's as the result of a Linq Query named "localCustomers" which contains 100 or so Customer ID's.I'm would like use this list to query and access customers' info on the whole group. Been searching on how to do this but no luck. It's easy enough with one customer ID, but how do I do it with an arrayList as the parameter? Here's my latest attempt but it's not working.
I have a collection of objects that I want to use LINQ in order to filter out only objects that have properties that meet a certain criteria. I am not big on LINQ so I am not sure how to do this.
I create a basic LINQ statement and get the records this way
Dim lr As IEnumerable(Of LogRecord) = From rr In _logRecords where rr.username="something"
but I only want to add that where condition if someone actually filled in a textbox.
I have other conditions to do the same thing with.
How do you reference a LINQ object that you have created such as a list, in your HTML? I have seen examples of how to do this using MVC, but I am using Web Forms. Here is my LINQ :
[Code]....
And I want to be able to for example check if my linq returns any data and if so iterate through it using a foreach loop in my HTML. change my linq so that it returns a generic list rather than what it is doing at the moment.
Private Sub MakeMeSomeXmlBeforeRyanGetsAngry() Dim db As New MyDBDataContext Dim customer = From c In db.Customers Select c Dim dcs As New DataContractSerializer(GetType(Customer)) Dim sb As StringBuilder = New StringBuilder Dim writer As XmlWriter = XmlWriter.Create(sb) dcs.WriteObject(writer, customer) Dim xml As String = sb.ToString Response.Write(xml) End Sub
I am attempting to serialize my linq collection of customers. But it keeps throwing
Type 'System.Data.Linq.DataQuery`1[MyDB.Customer]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types.
My issue is that I have already marked the dbml Serialization Mode to UniDirectional and when I check the dbml codebehind all of the DataContract()> and DataMember()> elements are there.
I am not sure how to proceed. I have tried adding various dataloadoptions and setting deferredloading to false, but no luck.
I am use the new ASP.NET MVC 2 and Entity Framework, but when I try to create a new view with strongly-typed option selected, the entity objects is not appears at dropdown and I cannot use the view creation wizard. I recompile the solution, but still not appears yet. Have any workaround that I forgot to do to enable the entities to be displayed at dropdownlist ?
Currently i am having a list like List<Tickets> allTickets.I need to select in the same list some corresponding info about the ticket writer like List<Ticket, aspnet_User>.
I have two business objects mapped via LINQ to tables. One of the objects contains an instance of the other object and share a key as an identifier.I want to retrieve Class A and within class A all of Class B's values as well. What I am doing is this:
[Code]....
[Code]....
This seems a little clunky, as in slow. Is there a better way to get the Class B (User) information without making a query every time?
I have written a page which uses Linq to query the database and bind the resulting IQueryable to a datagrid. I have a partial class which contains extra properties which derive their values based on other values brought in from the database.
Sorting works fine on fields that are actually in the database but not for the derived fields. When I attempt to sort on such a field I get an error saying "The member 'Trip.Difference' has no supported translation to SQL. how to allow sorting on these derived fields?
I'm new to linq. here is the scenario i need to write query for.I have a "Candidate" table with a varchar property "Skill"I have the table OR-mapped with LINQ to SQL on dbml file. Now I want to write linq query that:Selects all Candidates that have skill containing any of the keywords from ("asp.net","php","java")
I have a list of objects (List1) and I am trying to make a copy of this list (List2) and then change one of the fields in the new list.I used :
List<MyObj> List2 = new List<MyObj>(); List2.AddRange(List1); I alos tried: List<MyObj> List2 = new List<MyObj>(List1); But regardless of the method, when I do: foreach (MyObj o in List2) o.some_field = 2
it not only changes the field in Lis2 but alos in List1. Not sure what I am missing here.
I have a list of objects and I would like to create my own custom control that pages through the list using Jquery to make the Ajax calls to my pager methods. I've had some experience with Jquery but need a helping hand and I really don't want to use update panels etc. So the scenario is.....user clicks next, the C# method is called using Ajax, the code gets the relevant data and sends re-populates the UI with the next item in the list.