linq

How to move records from one table to another in linq

I have a ProductLevel table in an SQL database. It contains the products for a store. I want to copy these records into a ProductLevelDaily table at the time the user logs onto the hand held device in the morning. As they scan items the bool goes from false to true so at anytime they can see what items are left to scan/check. From the ...

LINQ query to return whether an item is found in an array?

I am learning LINQ, and I am not sure how to write a query to return a boolean indicating whether an item is found in an array. I have a very simple list: var targetProperties = new string[] { "SelectedDate", "SelectedMonth" }; I need to write a LINQ query that will return true if an item passed in is in the array, and false if it isn...

LINQ Query to find all tags?

I have an application that manages documents called Notes. Like a blog, Notes can be searched for matches against one or more Tags, which are contained in a Note.Tags collection property. A Tag has Name and ID properties, and matches are made against the ID. A user can specify multiple tags to match against, in which case a Note must con...

cant group by using linq

i am using vb.net and dataset have two table and relation , i query only on the first table but i cant use group by on any filed of the table it give Definition of method 'GroupBy' is not accessible in this context here is the code Dim Groups = From n In dataSetTableAsEnumerable _ Group By n.filedName Into Group ...

Simple LINQ insert record not working

I have an .mdf file which I'm trying to add a record to, using linq in C#. My code is: dbDataContext context = new dbDataContext(); book b = new book(); b.title = "Test Book"; b.isbn = "123789"; context.books.InsertOnSubmit(b); context.SubmitChanges(); When this code runs, the record is not inserted, and I get no error messages. If I ...

Which xml structure allows faster Add/Del/Update

Which XML structure allows me faster adding,deleting,updating of a node? My assumption is the first one as the xml hierarchy is not that deep. What do you think ? <Departments> <Department Id="a Guid" IsVisible="True" /> </Departments> OR <Departments> <Department> <Id>a Guid</Id> <IsVisible>True</IsVisible> <...

How to use Func with Entity Data Context?

i writed below codes MyCustomer.cs must return List which is type of Customer entity. İ used Func method. I want to do this: return erpEntityCtx.Customer.Select(select).ToList<TResult>(); BUT error return to me: Has some invalid argument. i can use this: return erpEntityCtx.Customer.Select(c=>c.Name).ToList<TResult>(); However ...

How can i develop lRepository<TModel> in Manager class in Enttiy?

i try to write manager class. But i can not use that : return erpObj.Get(predicate); How can i do that? namespace Erp.BLL.Manager { public interface ILoad { List<TResult> Load<TKey,TResult>(List<TKey> list, Func<TKey, TResult> select); } public interface IRepository<TModel> { List<TModel> Get(Fun...

Sort of Insert/Update statement in LINQ to XML for XElement

I have this xml structure: <Departments> <Department Id="a Guid" IsVisible="True" /> </Departments> I have created the xml file with: <Departments /> Now I want to add a bool value to IsVisible for a certain Id If that Id does not exist in the xml file I want to make an insert creating a new Department with Id + IsVisible. My...

Filter the "Includes" table on Entity Framework query

This is for Entity Framework for .NET 3.5: I have the need to query a table and include a collection of the "many" table of a one-to-many relationship. I'm trying to filter that collection as part of the query - I'm pretty new to Entity Framework, and I'm having trouble figuring it out. Simplified example: Author has Books, and Book h...

how to add/insert conditional node into XML using linq to XML

I generated an xml file like this: XElement employees = new XElement("Work", new XElement("record", new XElement("Name", textBox1.Text), new XElement("Phone", "206-555-0144"), new XElement("Address", new XElement("Street1", "123 Main St"), ...

Querying with LINQ basic question

I actually have two questions today, but they are both small :-) 1) Where is a good resource for learning linq/sql selections in C#? 2) Say I have a table called Model, with properties Name, Color, Shape. How do I do a query to select only the rows which DONT have null values in any column. I've tried: var d = database.Portfolio.Sele...

LINQ to SQL join two tables to select parent table twice based on two different columns from child table

I'd like to get suggestion in both C# and VB.NET I have two tables Employees and CafeLogs. Some employees can be cashiers and also customers at the Cafe shop. Table structures: Employees: EmployeeId(PK) , FirstName, LastName CafeLogs: LogId (PK), CashierId, EmployeeId, Value, => CashierId and EmployeeId are the data from column Emp...

Are LINQ .Last, .Skip, etc. methods optimized for arrays or List<T>?

I'm wondering if LINQ methods like .Last and .Skip are optimized for arrays, List and the such. E.g. for an array I could do _array[_array.Length] to get the last element. Does _array.Last() actually enumerate through all elements and then return the last or is there actually some optimization built in? Might have to forgo fluency for p...

What to return from a WCF service when using linq?

Hello, What should i return from a WCF service when using Linq? Eg :- var res = from q in context.cust select q; The Linq follows Deferred Execution and thus the statement doesn't do anything until a for loop is ran. This means i can't just return res. Then what should i return? Do i need to write a for loop and populate objects an...

Generating XML with an xsd in VS2010 using LINQ

I think the title says it all. I've used Linq2SQL lots and am familiar with most of the concepts (up to and including extending an ObjectContext) but with regards to Linq2XML, I'm a little lost. I now have a need to generate some complex XML and I'd like to use the simplicity of LINQ. Previously, I've used XMLDocuments and programatic...

How bind Checklistbox inside repeater control having datasource as LINQ

Hi All, i my website i am using Repeater control which further contain checkboxlist control. Now my problem is that i have successfully bind "Parameter Type" in repeater control but when i am binding checkbox values, it does't appears in display <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <...

How do I display the name from one sql table linked by an id?

bit of a newbie to mvc. i am having trouble with the following scenario: I have a view with the following: <tr> <% foreach (var game in (IEnumerable<Game>)ViewData["Game"]) { %> <td> <input type="checkbox" name="selectedObjects" value="<%=game.Id%>" /> </td> <td> ...

LINQ Join Where Clause

Hello all. I'm struggling with a join/where clause with what is a rather simple sql select statement. I am trying to retrieve a list of product information from tb1 with the where condition behind situated in tbl2 but this must be joined by three different columns. so the SQL would look something along the lines of: SELECT tb1.* ...

How should I compare values in two lists?

I have two lists List 01 => { A, B, C, D, E } List 02 => { F, F, F, F, E } I need to check if one element of List 02 exists in List 01, so the following should be false. List 01 => { A, B, C, D, E } List 02 => { F, F, F, F, F } // no element matches And here it should be true. List 01 => { A, B, C, D, E } List 02 => { F, F, F, F, ...