Search Results

Search found 6744 results on 270 pages for 'linq to entities'.

Page 19/270 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • Linq to Entities : using ToLower() on NText fields

    - by Julien N
    I'm using SQL Server 2005, with a case sensitive database.. In a search function, I need to create a Linq To Entities (L2E) query with a "where" clause that compare several strings with the data in the database with these rules : The comparison is a "Contains" mode, not strict compare : easy as the string's Contains() method is allowed in L2E The comparison must be case insensitive : I use ToLower() on both elements to perform an insensitive comparison. All of this performs really well but I ran into the following Exception : "Argument data type ntext is invalid for argument 1 of lower function" on one of my fields. It seems that the field is a NText field and I can't perform a ToLower() on that. What could I do to be able to perform a case insensitive Contains() on that NText field ?

    Read the article

  • LiNQ to Entities, Include less

    - by Freddy
    Hi, If you are making a LinQ to entities expression for ClassA where A has a relation to ClassB like this: var temp = from p in myEntities.ClassA.Include("ClassB") where ... select p; You will get a set of ClassA:s with the reference to ClassB loaded. The thing in my case is that I dont really need to load ALL the ClassB-references, just a few of them. But I dont want to loop through the list of ClassA:s and load them individually, i want my database operations to be fewer and bigger instead of reading small chunks here and there. Is it possible to put some kind of restrictions on which references to include or do you have to accept this all or nothing style?

    Read the article

  • SQL's Rownumber with Linq-to-entities

    - by mariki
    I am converting my project to use EF and also want to covert stored procedures into Linq-to-entities queries. This my SQL query (simple version) that I have trouble to convert: SELECT CategoryID, Title as CategoryTitle,Description, LastProductTitle,LastProductAddedDate FROM ( SELECT C.CategoryID, C.Title,C.Description, C.Section, P.Title as LastProductTitle, P.AddedDate as LastProductAddedDate, ROW_NUMBER() OVER (PARTITION BY P.CategoryID ORDER BY P.AddedDate DESC) AS Num FROM Categories C LEFT JOIN Products P ON P.CategoryID = C.CategoryID ) OuterSelect WHERE OuterSelect.Num = 1 In words: I want to return all Categories (from Categories table) and title and date of addition of the product (from Products table) that was added last to this category. How can I achieve this using Entity frame work query? In most efficient way.

    Read the article

  • Binding Linq To Entities query results to a datagridview

    - by Nickson
    I just started playing with Linq to entities in a windows forms application and am not understanding one behavior that looks so simple though. If i type code below, i get ReadOnly records in my dataGridView Dim x = From n in Table1 _ Select n.FirstName, n.LastName, N.Department DataGridView1.DataSource = x But if i type the following code, i get editable rows in my dataGridView Dim x = From n in Table1 _ Select n DataGridView1.DataSource = x So, basically if i specify the column names to select and databind to my DataGridView1, the rows are readonly but if i do not specify the column names and databind to the DataGridView, the rows are editable and i don't understand why.

    Read the article

  • Linq to Entities - left Outer Join

    - by user255234
    Could you please help me to figure this one out? I need to replace a join with OSLP table with OUTER join. Seems a bit tricky for someone who is not an expert in Linq to entities. How would I do that? var surgeonList = ( from item in context.T1_STM_Surgeon .Include("T1_STM_SurgeonTitle") .Include("OTER") where item.ID == surgeonId join reptable in context.OSLP on item.Rep equals reptable.SlpCode select new { ID = item.ID, First = item.First, Last = item.Last, Rep = reptable.SlpName, Reg = item.OTER.descript, PrimClinic = item.T1_STM_ClinicalCenter.Name, Titles = item.T1_STM_SurgeonTitle, Phone = item.Phone, Email = item.Email, Address1 = item.Address1, Address2 = item.Address2, City = item.City, State = item.State, Zip = item.Zip, Comments = item.Comments, Active = item.Active, DateEntered = item.DateEntered }).ToList(); Thanks in advance!!

    Read the article

  • How to substr html entities properly?

    - by Emily
    Hi everyone. I have like this : $mytext="that&#039;s really &quot;confusing&quot; and &lt;absolutly&gt; silly"; echo substr($mytext,0,6); The output in this case will be : that&# instead of that's What i want is to count html entities as 1 character then substr, because i always end up with breaked html or some obscure characters at the end of text. Please don't suggest me to html decode it then substr then encode it, i want a clean method :) Thanks

    Read the article

  • How to write Asynchronous LINQ query?

    - by Morgan Cheng
    After I read a bunch of LINQ related stuff, I suddenly realized that no articles introduce how to write asynchronous LINQ query. Suppose we use LINQ to SQL, below statement is clear. However, if the SQL database responds slowly, then the thread using this block of code would be hindered. var result = from item in Products where item.Price > 3 select item.Name; foreach (var name in result) { Console.WriteLine(name); } Seems that current LINQ query spec doesn't provide support to this. Is there any way to do asynchronous programming LINQ? It works like there is a callback notification when results are ready to use without any blocking delay on I/O.

    Read the article

  • Entity Framework: Delete Object and its related entities

    - by Waheed
    Hi, Does anyone know how to delete an object and all of it's related entities. For example i have tables, Products, Category, ProductCategory and productDetails, the productCategory is joining table of both Product and Category. I have red from http://msdn.microsoft.com/en-us/library/bb738580.aspx that Deleting the parent object also deletes all the child objects in the constrained relationship. This result is the same as enabling the CascadeDelete property on the association for the relationship. I am using this code Product productObj = this.ObjectContext.Product.Where(p => p.ProductID.Equals(productID)).First(); if (!productObj.ProductCategory.IsLoaded) productObj.ProductCategory.Load(); if (!productObj.ProductDetails.IsLoaded) productObj.ProductDetails.Load(); //my own methods. base.Delete(productObj); base.SaveAllObjectChanges(); But i am getting error on ObjectContext.SaveChanges(); i.e A relationship is being added or deleted from an AssociationSet 'FK_ProductCategory_Product'. With cardinality constraints, a corresponding 'ProductCategory' must also be added or deleted. Thanks in advance....

    Read the article

  • Should the entity framework + self tracking entities be saving me time

    - by sipwiz
    I've been using the entity framework in combination with the self tracking entity code generation templates for my latest silverlight to WCF application. It's the first time I've used the entity framework in a real project and my hope was that I would save myself a lot of time and effort by being able to automatically update the whole data access layer of my project when my database schema changed. Happily I've found that to be the case, updating my database schema by adding a new table, changing column names, adding new columns etc. etc. can be propagated to my business object classes by using the update from database option on the entity framework model. Where I'm hurting is the CRUD operations within my WCF service in response to actions on my Silverlight client. I use the same self tracking entity framework business objects in my Silverlight app but I find I'm continually having to fight against problems such as foreign key associations not being handled correctly when updating an object or the change tracker getting confused about the state of an object at the Silverlight end and the data access operation within the WCF layer throwing a wobbly. It's got to a point where I have now spent more time dealing with this quirks than I have on my previous project where I used Linq-to-SQL as the starting point for rolling my own business objects. Is it just me being hopeless or is the self tracking entities approach something that should be avoided until it's more mature?

    Read the article

  • Linq to Entities Joins

    - by Bob Avallone
    I have a question about joins when using Linq to Entities. According to the documentation the use on the join without a qualifier performs like a left outer join. However when I execute the code below, I get a count returned of zero. But if I comment out the three join lines I get a count of 1. That would indicate that the join are acting as inner join. I have two questions. One which is right inner or outer as the default? Second how do I do the other one i.e. inner or outer? The key words on inner and outer do not work. var nprs = (from n in db.FMCSA_NPR join u in db.FMCSA_USER on n.CREATED_BY equals u.ID join t in db.LKUP_NPR_TYPE on n.NPR_TYPE_ID equals t.ID join s in db.LKUP_AUDIT_STATUS on n.NPR_STATUS_ID equals s.ID where n.ROLE_ID == pRoleId && n.OWNER_ID == pOwnerId && n.NPR_STATUS_ID == pNPRStatusId && n.ACTIVE == pActive select n).ToList(); if (nprs.Count() == 0) return null;

    Read the article

  • Linq-to-sql Compiled Query returns object NOT belonging to submitted DataContext ?

    - by Vladimir Kojic
    Compiled query: public static class Machines { public static readonly Func<OperationalDataContext, short, Machine> QueryMachineById = CompiledQuery.Compile((OperationalDataContext db, short machineID) => db.Machines.Where(m => m.MachineID == machineID).SingleOrDefault() ); public static Machine GetMachineById(IUnitOfWork unitOfWork, short id) { Machine machine; // Old code (working) //var machineRepository = unitOfWork.GetRepository<Machine>(); //machine = machineRepository.Find(m => m.MachineID == id).SingleOrDefault(); // New code (making problems) machine = QueryMachineById(unitOfWork.DataContext, id); return machine; } It looks like compiled query is returning result from another data context [TestMethod] public void GetMachinesTest() { using (var unitOfWork = IoC.Get<IUnitOfWork>()) { // Compile Query var machine = Machines.GetMachineById(unitOfWork, 3); } using (var unitOfWork = IoC.Get<IUnitOfWork>()) { var machineRepository = unitOfWork.GetRepository<Machine>(); // Get From Repository var machineFromRepository = machineRepository.Find(m => m.MachineID == 2).SingleOrDefault(); var machine = Machines.GetMachineById(unitOfWork, 2); VerifyHuskyHostMachine(machineFromRepository, 2, "Machine 2", "222222", "H400RS", "MachineIconB.xaml", false, true, LicenseType.Licensed, InterfaceType.HuskyHostV2, "10.0.97.2:8080", "10.0.97.2", 8080, "4.0"); VerifyHuskyHostMachine(machine, 2, "Machine 2", "222222", "H400RS", "MachineIconB.xaml", false, true, LicenseType.Licensed, InterfaceType.HuskyHostV2, "10.0.97.2:8080", "10.0.97.2", 8080, "4.0"); Assert.AreSame(machineFromRepository, machine); // FAIL } } If I run other (complex) unit tests I'm getting as expected: An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. Another Important information is that this test is under TransactionScope! UPDATE: It looks like next link is describing similar problem (is this bug solved ?): http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/9bcffc2d-794e-4c4a-9e3e-cdc89dad0e38

    Read the article

  • What join in Linq i have to use to do what i want?

    - by Garcia Julien
    Hi, I have two dataset from different server. I have result like that (if image doesn't work my data) The problem is at last, i've got only the result from the first table like that And i would like to have all the result for different job type like that asset job jan feb mar ... 5000 acc 10 11 12 5000 over 10 11 12 The problem is not solve with a right join because it's the same problem Could you help me? Thank Ju

    Read the article

  • Should I invest time in learning about OR\M or LINQ?

    - by Peter Smith
    I'm a .NET web developer primarily who occasionally writes console applications to mine data, cleanup tasks, etc. Most of what I do winds up involving a database which I currently design via sql server management studio, using stored procedures, and query analyzer. I also create a lot of web services which are consumed via AJAX applications. Do these technologies really help you in speeding up development times? Do you still have to build the database or object code first?

    Read the article

  • How to have a where clause on an insert or an update in Linq to Sql?

    - by Kelsey
    I am trying to convert the following stored proc to a LinqToSql call (this is a simplied version of the SQL): INSERT INTO [MyTable] ([Name], [Value]) SELECT @name, @value WHERE NOT EXISTS(SELECT [Value] FROM [MyTable] WHERE [Value] = @value) The DB does not have a constraint on the field that is getting checked for so in this specific case the check needs to be made manually. Also there are many items constantly being inserted as well so I need to make sure that when this specific insert happens there is no dupe of the value field. My first hunch is to do the following: using (TransactionScope scope = new TransactionScope()) { if (Context.MyTables.SingleOrDefault(t => t.Value == in.Value) != null) { MyLinqModels.MyTable t = new MyLinqModels.MyTable() { Name = in.Name, Value = in.Value }; // Do some stuff in the transaction scope.Complete(); } } This is the first time I have really run into this scenario so I want to make sure I am going about it the right way. Does this seem correct or can anyone suggest a better way of going about it without having two seperate calls? Edit: I am running into a similar issue with an update: UPDATE [AnotherTable] SET [Code] = @code WHERE [ID] = @id AND [Code] IS NULL How would I do the same check with Linqtosql? I assume I need to do a get and then set all the values and submit but what if someone updates [Code] to something other than null from the time I do the get to when the update executes? Same problem as the insert...

    Read the article

  • Why does LINQ-to-SQL Paging fail inside a function?

    - by ssg
    Here I have an arbitrary IEnumerable<T>. And I'd like to page it using a generic helper function instead of writing Skip/Take pairs every time. Here is my function: IEnumerable<T> GetPagedResults<T>(IEnumerable<T> query, int pageIndex, int pageSize) { return query.Skip((pageIndex - 1) * pageSize).Take(pageSize); } And my code is: result = GetPagedResults(query, 1, 10).ToList(); This produces a SELECT statement without TOP 10 keyword. But this code below produces the SELECT with it: result = query.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); What am I doing wrong in the function?

    Read the article

  • How can I load class's part using linq to sql without anonymous class or additional class?

    - by ais
    class Test { int Id{get;set;} string Name {get;set;} string Description {get;set;} } //1)ok context.Tests.Select(t => new {t.Id, t.Name}).ToList().Select(t => new Test{Id = t.Id, Name = t.Name}); //2)ok class TestPart{ int Id{get;set;} string Name {get;set;} } context.Tests.Select(t => new TestPart{Id = t.Id, Name = t.Name}).ToList().Select(t => new Test{Id = t.Id, Name = t.Name}); //3)error Explicit construction of entity type 'Test' in query is not allowed. context.Tests.Select(t => new Test{Id = t.Id, Name = t.Name}).ToList(); Is there any way to use third variant?

    Read the article

  • How can I do more than one level of cascading deletes in Linq?

    - by Gary McGill
    If I have a Customers table linked to an Orders table, and I want to delete a customer and its corresponding orders, then I can do: dataContext.Orders.DeleteAllOnSubmit(customer.Orders); dataContext.Customers.DeleteOnSubmit(customer); ...which is great. However, what if I also have an OrderItems table, and I want to delete the order items for each of the orders deleted? I can see how I could use DeleteAllOnSubmit to cause the deletion of all the order items for a single order, but how can I do it for all the orders?

    Read the article

  • is there a better way to write this frankenstein LINQ query that searches for values in a child tabl

    - by MRV
    I have a table of Users and a one to many UserSkills table. I need to be able to search for users based on skills. This query takes a list of desired skills and searches for users who have those skills. I want to sort the users based on the number of desired skills they posses. So if a users only has 1 of 3 desired skills he will be further down the list than the user who has 3 of 3 desired skills. I start with my comma separated list of skill IDs that are being searched for: List<short> searchedSkillsRaw = skills.Value.Split(',').Select(i => short.Parse(i)).ToList(); I then filter out only the types of users that are searchable: List<User> users = (from u in db.Users where u.Verified == true && u.Level > 0 && u.Type == 1 && (u.UserDetail.City == city.SelectedValue || u.UserDetail.City == null) select u).ToList(); and then comes the crazy part: var fUsers = from u in users select new { u.Id, u.FirstName, u.LastName, u.UserName, UserPhone = u.UserDetail.Phone, UserSkills = (from uskills in u.UserSkills join skillsJoin in configSkills on uskills.SkillId equals skillsJoin.ValueIdInt into tempSkills from skillsJoin in tempSkills.DefaultIfEmpty() where uskills.UserId == u.Id select new { SkillId = uskills.SkillId, SkillName = skillsJoin.Name, SkillNameFound = searchedSkillsRaw.Contains(uskills.SkillId) }), UserSkillsFound = (from uskills in u.UserSkills where uskills.UserId == u.Id && searchedSkillsRaw.Contains(uskills.SkillId) select uskills.UserId).Count() } into userResults where userResults.UserSkillsFound > 0 orderby userResults.UserSkillsFound descending select userResults; and this works! But it seems super bloated and inefficient to me. Especially the secondary part that counts the number of skills found. Thanks for any advice you can give. --r

    Read the article

  • What is the difference between these two LINQ statements?

    - by jamone
    I had the 1nd statement in my code and found it not giving an accurate count, it was returning 1 when the correct answer is 18. To try and debug the problem I broke it out creating the 2nd statement here and the count returns 18. I just don't see what the difference is between these two. It seems like the 1st is just more compact. I'm currently running these two statements back to back and I'm sure that the database isn't changing between the two. int count = (from s in surveysThisQuarter where s.FacilityID == facility.LocationID select s.Deficiencies).Count(); vs var tempSurveys = from s in surveysThisQuarter where s.FacilityID == facility.LocationID select s; int count = 0; foreach (Survey s in tempSurveys) count += s.Deficiencies.Count();

    Read the article

  • How can i have different LINQ to XML quries based on two different condition?

    - by Subhen
    Hi , We want the query result should be assigned with two results based on some condition like following: var vAudioData = (from xAudioinfo in xResponse.Descendants(ns + "DIDL-Lite").Elements(ns + "item") if((xAudioinfo.Element(upnp + "artist")!=null) { select new RMSMedia { strAudioTitle = ((string)xAudioinfo.Element(dc + "title")).Trim() }; } else select new RMSMedia { strGen = ((string)xAudioinfo.Element(dc + "Gen")).Trim() }; The VarAudioData should contain both if and else condition values. I have added the if condition just to project , what is my needs, m quite sure though that we can not use if and else. Please help if there are any other approach to accomplish this. Thanks, Subhen

    Read the article

  • Is a full list returned first and then filtered when using linq to sql to filter data from a databas

    - by RJ
    This is probably a very simple question that I am working through in an MVC project. Here's an example of what I am talking about. I have an rdml file linked to a database with a table called Users that has 500,000 rows. But I only want to find the Users who were entered on 5/7/2010. So let's say I do this in my UserRepository: from u in db.GetUsers() where u.CreatedDate = "5/7/2010" select u (doing this from memory so don't kill me if my syntax is a little off, it's the concept I am looking for) Does this statement first return all 500,000 rows and then filter it or does it only bring back the filtered list?

    Read the article

  • How to avoid geometric slowdown with large Linq transactions?

    - by Shaul
    I've written some really nice, funky libraries for use in LinqToSql. (Some day when I have time to think about it I might make it open source... :) ) Anyway, I'm not sure if this is related to my libraries or not, but I've discovered that when I have a large number of changed objects in one transaction, and then call DataContext.GetChangeSet(), things start getting reaalllly slooowwwww. When I break into the code, I find that my program is spinning its wheels doing an awful lot of Equals() comparisons between the objects in the change set. I can't guarantee this is true, but I suspect that if there are n objects in the change set, then the call to GetChangeSet() is causing every object to be compared to every other object for equivalence, i.e. at best (n^2-n)/2 calls to Equals()... Yes, of course I could commit each object separately, but that kinda defeats the purpose of transactions. And in the program I'm writing, I could have a batch job containing 100,000 separate items, that all need to be committed together. Around 5 billion comparisons there. So the question is: (1) is my assessment of the situation correct? Do you get this behavior in pure, textbook LinqToSql, or is this something my libraries are doing? And (2) is there a standard/reasonable workaround so that I can create my batch without making the program geometrically slower with every extra object in the change set?

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >