Search Results

Search found 87713 results on 3509 pages for 'new linq baby'.

Page 10/3509 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Linq query - multiple where, with extension method

    - by Cj Anderson
    My code works for ORs as I've listed it below but I want to use AND instead of OR and it fails. I'm not quite sure what I'm doing wrong. Basically I have a Linq query that searches on multiple fields in an XML file. The search fields might not all have information. Each element runs the extension method, and tests the equality. Any advice would be appreciated. refinedresult = From x In theresult _ Where x.<thelastname>.Value.TestPhoneElement(LastName) Or _ x.<thefirstname>.Value.TestPhoneElement(FirstName) Or _ x.<id>.Value.TestPhoneElement(Id) Or _ x.<number>.Value.TestPhoneElement(Telephone) Or _ x.<location>.Value.TestPhoneElement(Location) Or _ x.<building>.Value.TestPhoneElement(building) Or _ x.<department>.Value.TestPhoneElement(Department) _ Select x Public Function TestPhoneElement(ByVal parent As String, ByVal value2compare As String) As Boolean 'find out if a value is null, if not then compare the passed value to see if it starts with Dim ret As Boolean = False If String.IsNullOrEmpty(parent) Then Return False End If If String.IsNullOrEmpty(value2compare) Then Return ret Else ret = parent.ToLower.StartsWith(value2compare.ToLower.Trim) End If Return ret End Function

    Read the article

  • Compile error when calling ToList() when accessing many to many with Linq To Entities

    - by KallDrexx
    I can't figure out what I am doing wrong. I have the following method: public IList<WObject> GetRelationshipMembers(int relId) { var members = from r in _container.ObjectRelationships where r.Id == relId select r.WObjects; return members.ToList<WObject>(); } This returns the following error: Instance argument: cannot convert from 'System.Linq.IQueryable<System.Data.Objects.DataClasses.EntityCollection<Project.DomainModel.Entities.WObject>>' to 'System.Collections.Generic.IEnumerable<Project.DomainModel.Entities.WObject>' How can I convert the EntityCollection to a list without lazy loading?

    Read the article

  • How to do a STAR search in LINQ

    - by aNui
    I'm not sure about clarity of the STAR word. I'm implementing a search method using linq-to-object in c#. And I want to do a search with * (star) operator like most of search apps or web can do. e.g. If I typed "p*", results should be everything starting with "p". And it should work for prefix star, suffix star or star in the middle. And it would be great if the search can do with "-" (minus/NOT) operator or "+" (plus/OR) operator or "AND" operator Thanks in advance.

    Read the article

  • Dynamic Linq Library Help

    - by Alon
    Hi, I have the following class: public class Item { public Dictionary<string, string> Data { get; set; } } and a list of it: List<Item> items; I need to filter and order this list dynamicly using SQL-Like strings. The catch is, that I need to order it by the Data dictionary. For example: Order By Data["lastname"] or Where Data["Name"].StartsWith("a"). I thought to use the dynamic linq library, but is there any way that my clients can write without the Data[]? For example: Name.StartsWith("abc") instead of Data["Name"].StartsWith("abc") ? Thank you.

    Read the article

  • Using LINQ to find a common prefix?

    - by Roger Lipscombe
    I've got two sequences: IEnumerable<string> x = new[] { "a", "b", "c" }; IEnumerable<string> y = new[] { "a", "b", "d", "e" }; I'd like to find the common prefix of these two sequences (i.e. "a", "b"). Is there a succinct way to do this in LINQ? Bear in mind that these aren't really IEnumerable<string>; they're IEnumerable<PathComponent>, where I have an implementation of IEqualityComparer<PathComponent>.

    Read the article

  • how to convert Database Hierarchical Data to XML using ASP.net 3.5 and LINQ

    - by mahdiahmadirad
    hello guys! i have a table with hierarchical structure. like this: and table data shown here: this strategy gives me the ability to have unbounded categories and sub-categories. i use ASP.net 3.5 SP1 and LINQ and MSSQL Server2005. How to convert it to XML? I can Do it with Dataset Object and ".GetXML()" method. but how to implement it with LINQtoSQL or LINQtoXML??? or if there is another simpler way to perform that? what is your suggestion? the best way? I searched the web but found nothing for .net 3.5 featuers.

    Read the article

  • LINQ expression precedence with Skip(), Take() and OrderBy()

    - by Robert Koritnik
    I'm using LINQ to Entities and display paged results. But I'm having issues with the combination of Skip(), Take() and OrderBy() calls. Everything works fine, except that OrderBy() is assigned too late. It's executed after result set has been cut down by Skip() and Take(). So each page of results has items in order. But ordering is done on a page handful of data instead of ordering of the whole set and then limiting those records with Skip() and Take(). How do I set precedence with these statements? My example (simplified) var query = ctx.EntitySet.Where(/* filter */).OrderBy(/* expression */); int total = query.Count(); var result = query.Skip(n).Take(x).ToList();

    Read the article

  • LINQ Expression<Func<T, bool>> equavalent of .Contains()

    - by BK
    Has anybody got an idea of how to create a .Contains(string) function using Linq Expressions, or even create a predicate to accomplish this public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2) { var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>()); return Expression.Lambda<Func<T, bool>> (Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters); } Something simular to this would be ideal?

    Read the article

  • linq to sql using foreign keys returning iqueryable(of myEntity]

    - by Gern Blandston
    I'm trying to use Linq to SQL to return an IQueryable(of Project) when using foreign key relationships. Using the below schema, I want to be able to pass in a UserId and get all the projects created for the company the user is associated with. DB tables: Projects Projid ProjCreator FK (UserId from UserInfo table) Companyid FK (CompanyID from Companies table) UserInfo UserID PK Companyid FK Companies CompanyId PK Description I can get the iqueryable(of project) when simply getting the ProjectCreator with this: Return (From p In db.Projects _ Where p.ProjectCreator = Me.UserId) But I'm having trouble getting the syntax to get a iqueryable(of projects) when using foreign keys. Below gives me an IQueryable(of anonymous) but I can't seem to convince it to give me an IQueryable(of project) even if I try to cast it: Dim retval = (From p In db.Projects _ Join c In db.Companies On p.CompanyId Equals c.CompanyId _ Join u In db.UserInfos On u.CompanyId Equals c.CompanyId _ Where u.Login = UserId)

    Read the article

  • Use delegate for Projection in Linq to SQL

    - by Redeemed1
    I have code something like this in an IRepository implementation in Linq to Sql: var newlist = from h in list where h.StringProp1 == "1" select new MyBusinessBO{ firstProp = h.StringProp1, secondProp = h.StringProp2 }; The projection into MyBusinessBO is not difificult but when the Business Object has many properties the projection code becomes very lengthy. Also, as the projection can occur in several places in the Repository we break the DRY principle. Is there any way to abstract out the projection or replace it with a delegate? I.e. replace the code firstProp = h.StringProp1, secondProp = h.StringProp2 with something reusable?

    Read the article

  • How to Expression.Invoke an arbitrary LINQ 2 SQL Query

    - by Remus Rusanu
    Say I take an arbitrary LINQ2SQL query's Expression, is it possible to invoke it somehow? MyContext ctx1 = new MyContext("..."); var q = from t in ctx1.table1 where t.id = 1 select t; Expression qe = q.Expression; var res = Expression.Invoke(qe); This throws ArgumentException "Expression of type System.Linq.IQueryable`1[...]' cannot be invoked". My ultimate goal is to evaluate the same query on several different data contexts.

    Read the article

  • VB.NET LINQ Result Set Manipulation.

    - by davemackey
    I have a table that looks like this: ID / Description / textValue / dateValue / timeValue / Type 1 / FRRSD / NULL / 2010-04-16 00:00:00.000 / NULL / classdates Now I've got a LINQ command to pull only the rows where the type is classdates from this table: Dim dbGetRegisterDates As New dcConfigDataContext Dim getDates = (From p In dbGetRegisterDates.webConfigOptions _ Where p.Type = "classdates" _ Select p) I now want to display the data in five different labels like so: lblClass1.Text = "Your class is from " & getDates.Description("FRRSD").dateValue & "to " & getDates.Description("FRRCD").dateValue Basically, I want to pull a row based on the description column value and then return the datevalue column value from that same row.

    Read the article

  • How to turn this linq query to lazy loading

    - by Luke101
    I would like to make a certain select item to lazy load latter in my linq query. Here is my query var posts = from p in context.post where p.post_isdeleted == false && p.post_parentid == null select new { p.post_date, p.post_id, p.post_titleslug, p.post_votecount, FavoriteCount = context.PostVotes.Where(x => x.PostVote_postid == p.post_id).Count() //this should load latter }; I have deleted the FavoriteCount item in the select query and would like it to ba added later based on certain conditions. Here is the way I have it lazy loaded if (GetFavoriteInfo) { posts = posts.Select(x => new { FavoriteCount = context.PostVotes.Where(y => y.PostVote_postid == x.post_id).Count() }); } I am getting a syntax error with this the above query. How do I fix this

    Read the article

  • Custom Grid LINQ to SQL help

    - by user488361
    Following is my custome cotrol grid... public partial class LinqGrid : UserControl { object tmpDataTable = new object(); public LinqGrid() { InitializeComponent(); } public void Bind(System.Data.Linq.Table listSource) where T : class { Project.dbClassesDataContext dbc = new Project.dbClassesDataContext(); tmpDataTable = listSource; var query = (from c in listSource select c); dgvRecords.DataSource = query.Take(10).ToList(); } private void btnNext_Click(object sender, EventArgs e) { // now what i have to do here if i want next 10 records.....means how to retrive tmpDataTable object here... ??? i can't find Type of variable....?? plz help me.... } }

    Read the article

  • Linq to Sql: Update Entity throug a new Object

    - by Dänu
    Hey Guys I'd like to update an entity via linq, but since I edit the entity in a view after serializing it, I don't have direct access to the entity inside the data context. I could do it like this: entity.property1 = obj.property1; entity.property2 = obj.property2; ... thats not cool... not cool at all. Next thing I tried is to do it via .attach() like so: context.Table.attach(entity, obj); doesn't work either. So is there another option short of reflection?

    Read the article

  • Can't combine "LINQ Join" with other tables

    - by FullmetalBoy
    The main problem is that I recieve the following message: "base {System.SystemException} = {"Unable to create a constant value of type 'BokButik1.Models.Book-Author'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."}" based on this LinQ code: IBookRepository myIBookRepository = new BookRepository(); var allBooks = myIBookRepository.HamtaAllaBocker(); IBok_ForfattareRepository myIBok_ForfattareRepository = new Bok_ForfattareRepository(); var Book-Authors = myIBok_ForfattareRepository.HamtaAllaBok_ForfattareNummer(); var q = from booknn in allBooks join Book-Authornn in Book-Authors on booknn.BookID equals Book-Authornn.BookID select new { booknn.title, Book-AuthorID }; How shall I solve this problem to get a class instance that contain with property title and Book-AuthorID? // Fullmetalboy I also have tried making some dummy by using "allbooks" relation with Code Samples from the address http://www.hookedonlinq.com/JoinOperator.ashx. Unfortunately, still same problem. I also have taken account to Int32 due to entity framework http://msdn.microsoft.com/en-us/library/bb896317.aspx. Unfortunatley, still same problem. Using database with 3 tables and one of them is a many to many relationship. This database is used in relation with entity framework Book-Author Book-Author (int) BookID (int) Forfattare (int) Book BookID (int) title (string) etc etc etc

    Read the article

  • Handling auto-incrementing IDENTITY SQL Server fields with LINQ to SQL in C#

    - by Maxim Z.
    I'm building an ASP.NET MVC site that uses LINQ to SQL to connect to SQL Server, where I have a table that has an IDENTITY bigint primary key column that represents an ID. In one of my code methods, I need to create an object of that table to get its ID, which I will place into another object based on another table (FK-to-PK relationship). At what point is the IDENTITY column value generated and how can I obtain it from my code? Is the right approach to: Create the object that has the IDENTITY column Do an InsertOnSubmit() and SubmitChanges() to submit the object to the database table Get the value of the ID property of the object

    Read the article

  • LINQ-to-SQL class doesn't implement INotifyPropertyChanging & INotifyPropertyChanged if pulling from

    - by Traples
    I modified my data source in my LINQ-to-SQL class (by the old delete and drag back in method), and was surprised to see the INotifyPropertyChanging & INotifyPropertyChanged interfaces no longer implemented in the generated classes (MyDb.designer.cs). The methods for the individual fields went from looking like this... [Column(Storage="_Size", DbType="NVarChar(100)")] public string Size { get { return this._Size; } set { if ((this._Size != value)) { this.OnSizeChanging(value); this.SendPropertyChanging(); this._Size = value; this.SendPropertyChanged("Size"); this.OnSizeChanged(); } } } To looking like this... [Column(Storage="_Size", DbType="NVarChar(100)")] public string Size { get { return this._Size; } set { if ((this._Size != value)) { this._Size = value; } } } Any ideas on why this happens and how it will affect my application?

    Read the article

  • Dynamic where clause in LINQ - with column names available at runtime

    - by sandesh247
    Disclaimer: I've solved the problem using Expressions from System.Linq.Expressions, but I'm still looking for a better/easier way. Consider the following situation : var query = from c in db.Customers where (c.ContactFirstName.Contains("BlackListed") || c.ContactLastName.Contains("BlackListed") || c.Address.Contains("BlackListed")) select c; The columns/attributes that need to be checked against the blacklisted term are only available to me at runtime. How do I generate this dynamic where clause? An additional complication is that the Queryable collection (db.Customers above) is typed to a Queryable of the base class of 'Customer' (say 'Person'), and therefore writing c.Address as above is not an option.

    Read the article

  • Mixing LINQ to SQL with properties of objects in a generic list

    - by BPotocki
    I am trying to accomplish something like this query: var query = from a in DatabaseTable where listOfObjects.Any(x => x.Id == a.Id) select a; Basically, I want to filter the results where a.Id equals a property of one of the objects in the generic list "listOfObjects". I'm getting the error "Local sequence cannot be used in LINQ to SQL implementation of query operators except the Contains() operator." Any ideas on how to filter this in an easily readable way using "contains" or another method? Thanks in advance.

    Read the article

  • LINQ Lycanthropy: Transformations into LINQ

    LINQ is one of the few technologies that you can start to use without a lot of preliminary learning. Also, it lends itself to learning by trying out examples. With Michael Sorens' help, you can watch as your conventional C# code changes to ravenous LINQ before your very eyes. Join SQL Backup’s 35,000+ customers to compress and strengthen your backups "SQL Backup will be a REAL boost to any DBA lucky enough to use it." Jonathan Allen. Download a free trial now.

    Read the article

  • Linq-to-XML query to select specific sub-element based on additional criteria

    - by BrianLy
    My current LINQ query and example XML are below. What I'd like to do is select the primary email address from the email-addresses element into the User.Email property. The type element under the email-address element is set to primary when this is true. There may be more than one element under the email-addresses but only one will be marked primary. What is the simplest approach to take here? Current Linq Query (User.Email is currently empty): var users = from response in xdoc.Descendants("response") where response.Element("id") != null select new User { Id = (string)response.Element("id"), Name = (string)response.Element("full-name"), Email = (string)response.Element("email-addresses"), JobTitle = (string)response.Element("job-title"), NetworkId = (string)response.Element("network-id"), Type = (string)response.Element("type") }; Example XML: <?xml version="1.0" encoding="UTF-8"?> <response> <response> <contact> <phone-numbers/> <im> <provider></provider> <username></username> </im> <email-addresses> <email-address> <type>primary</type> <address>[email protected]</address> </email-address> </email-addresses> </contact> <job-title>Account Manager</job-title> <type>user</type> <expertise nil="true"></expertise> <summary nil="true"></summary> <kids-names nil="true"></kids-names> <location nil="true"></location> <guid nil="true"></guid> <timezone>Eastern Time (US &amp; Canada)</timezone> <network-name>Domain</network-name> <full-name>Alice</full-name> <network-id>79629</network-id> <stats> <followers>2</followers> <updates>4</updates> <following>3</following> </stats> <mugshot-url> https://assets3.yammer.com/images/no_photo_small.gif</mugshot-url> <previous-companies/> <birth-date></birth-date> <name>alice</name> <web-url>https://www.yammer.com/domain.com/users/alice</web-url> <interests nil="true"></interests> <state>active</state> <external-urls/> <url>https://www.yammer.com/api/v1/users/1089943</url> <network-domains> <network-domain>domain.com</network-domain> </network-domains> <id>1089943</id> <schools/> <hire-date nil="true"></hire-date> <significant-other nil="true"></significant-other> </response> <response> <contact> <phone-numbers/> <im> <provider></provider> <username></username> </im> <email-addresses> <email-address> <type>primary</type> <address>[email protected]</address> </email-address> </email-addresses> </contact> <job-title>Office Manager</job-title> <type>user</type> <expertise nil="true"></expertise> <summary nil="true"></summary> <kids-names nil="true"></kids-names> <location nil="true"></location> <guid nil="true"></guid> <timezone>Eastern Time (US &amp; Canada)</timezone> <network-name>Domain</network-name> <full-name>Bill</full-name> <network-id>79629</network-id> <stats> <followers>3</followers> <updates>1</updates> <following>1</following> </stats> <mugshot-url> https://assets3.yammer.com/images/no_photo_small.gif</mugshot-url> <previous-companies/> <birth-date></birth-date> <name>bill</name> <web-url>https://www.yammer.com/domain.com/users/bill</web-url> <interests nil="true"></interests> <state>active</state> <external-urls/> <url>https://www.yammer.com/api/v1/users/1089920</url> <network-domains> <network-domain>domain.com</network-domain> </network-domains> <id>1089920</id> <schools/> <hire-date nil="true"></hire-date> <significant-other nil="true"></significant-other> </response> </response>

    Read the article

  • How to create Query syntax for multiple DataTable for implementing IN operator of Sql Server

    - by Shantanu Gupta
    I have fetched 3-4 tables by executing my stored procedure. Now they resides on my dataset. I have to maintain this dataset for multiple forms and I am not doing any DML operation on this dataset. Now this dataset contains 4 tables out of which i have to fetch some records to display data. Data stored in tables are in form of one to many relationship. i.e. In case of transactions. N records per record. Then these N records are further mapped to M records of 3rd table. Table 1 MAP_ID GUEST_ID DEPARTMENT_ID PARENT_ID PREFERENCE_ID -------------------- -------------------- -------------------- -------------------- -------------------- 19 61 1 1 5 14 61 1 5 15 15 61 2 4 10 18 61 2 13 23 17 61 2 20 26 16 61 40 40 41 20 62 1 5 14 21 62 1 5 15 22 62 1 6 16 24 62 2 3 4 23 62 2 4 9 27 62 2 13 23 25 62 2 20 24 26 62 2 20 25 28 63 1 1 5 29 63 1 1 8 34 63 1 5 15 30 63 2 4 10 33 63 2 4 11 31 63 2 13 23 32 63 40 40 41 35 65 1 NULL 1 36 65 1 NULL 1 38 68 2 13 22 37 68 2 20 25 39 68 2 23 27 40 92 1 NULL 1 Table 2 Department_ID Department_Name Parent_Id Parent_Name -------------------- ----------------------- --------------- ---------------------------------------------------------------------------------- 1 Food 1, 5, 6 Food, North Indian, South Indian 2 Lodging 3, 4, 13, 20, 23 Room, Floor, Non Air Conditioned, With Balcony, Without Balcony 40 New 40 SubNew TABLE 3 Parent_Id Parent_Name Preference_ID Preference_Name -------------------- ----------------------------------------------- ----------------------- ------------------- NULL NULL NULL NULL 1 Food 5, 8 North Indian, Italian 3 Room 4 Floor 4 Floor 9, 10, 11 First, Second, Third 5 North Indian 14, 15 X, Y 6 South Indian 16 Dosa 13 Non Air Conditioned 22, 23 With Balcony, Without Balcony 20 With Balcony 24, 25, 26 Mountain View, Ocean View, Garden View 23 Without Balcony 27 Mountain View 40 New 41 SubNew I have these 3 tables that are related in some fashion like this. Table 1 will be the master for these 2 tables i.e. table 2 and table 3. I need to query on them as SELECT Department_Id, Department_Name, Parent_Name FROM Table2 WHERE Department_Id in ( SELECT Department_Id FROM Table1 WHERE guest_id=65 ) SELECT Parent_Id, Parent_Name, Preference_Name FROM Table3 WHERE PARENT_ID in ( SELECT parent_id FROM Table1 WHERE guest_id=65 ) Now I need to use these queries on DataTables. So I am using Query Syntax for this and reached up to this point. var dept_list= from dept in DtMapGuestDepartment.AsEnumerable() where dept.Field<long>("PK_GUEST_ID")==long.Parse(63) select dept; This should give me the list of all departments that has guest id =63 Now I want to select all departments_name and parent_name from Table 2 where guest_id=63 i.e. departments that i fetched above. This same case will be followed for Table3. Please suggest how to do this. Thanks for keeping up patience for reading my question.

    Read the article

  • Linq to Entity Left Outer Join

    - by radman
    Hi All, I have an Entity model with Invoices, AffiliateCommissions and AffiliateCommissionPayments. Invoice to AffiliateCommission is a one to many, AffiliateCommission to AffiliateCommissionPayment is also a one to many I am trying to make a query that will return All Invoices that HAVE a commission but not necessarily have a related commissionPayment. I want to show the invoices with commissions whether they have a commission payment or not. Query looks something like: using (var context = new MyEntitities()) { var invoices = from i in context.Invoices from ac in i.AffiliateCommissions join acp in context.AffiliateCommissionPayments on ac.affiliateCommissionID equals acp.AffiliateCommission.affiliateCommissionID where ac.Affiliate.affiliateID == affiliateID select new { companyName = i.User.companyName, userName = i.User.fullName, email = i.User.emailAddress, invoiceEndDate = i.invoicedUntilDate, invoiceNumber = i.invoiceNumber, invoiceAmount = i.netAmount, commissionAmount = ac.amount, datePaid = acp.paymentDate, checkNumber = acp.checkNumber }; return invoices.ToList(); } This query above only returns items with an AffiliateCommissionPayment.

    Read the article

  • help with exception handling in linq

    - by stackoverflowuser
    I have the following code to retrieve customer name, total (orders ), sum (order details) for reach customer in Northwind database. The problem with below code is that it raises an exception since a few customers dont have any entry in orders table. I know using the query syntax (join) the exception can be avoided. I want to know if the same can be handled with the extension method syntax. CustomerOrderDataContext db = new CustomerOrderDataContext(); var customerOrders = db.Customers.Select(c => new { CompanyName = c.CompanyName, TotalOrders = c.Orders.Count(), TotalQuantity = c.Orders.SelectMany(o => o.Order_Details).Sum(o=>o.Quantity) });

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >