linq-to-entities

Why does Entity Framework generate slow overengineered SQL?

萝らか妹 提交于 2019-12-30 10:27:26
问题 I have this code: DbSet<TableName> table = ...// stored reference var items = from n in table where n.Name.ToUpper().Contains(searchString.ToUpper().Trim()) select n; WriteToLog( items.ToString() ); The last line outputs the generated SQL. Here's what I get: SELECT [Extent1].[Name] AS [Name], // all the other columns follow FROM (SELECT [TableName].[Name] AS [Name], // all the other columns follow FROM [dbo].[TableName] AS [TableName]) AS [Extent1] WHERE ( CAST(CHARINDEX(LTRIM(RTRIM(UPPER(@p_

Convert SQL Query to Linq (contains left joins)

匆匆过客 提交于 2019-12-30 07:33:11
问题 I have a query that works perfectly in SQL, but I'm having the damnedest time converting it to linq. The table (Table1 below) holds status changes for multiple record types. The join requires two fields to be set to create the valid join: A SubmissionId (pk of the table the status pertains to), and a SubmissionTypeId (determines what table the status pertains to). CREATE TABLE ##Table1 (Id int, Status varchar(50), SubmissionId int, SubmissionTypeId int) insert into ##Table1(Id, Status,

Error: The object cannot be deleted because it was not found in the ObjectStateManager

青春壹個敷衍的年華 提交于 2019-12-30 06:02:46
问题 Trying to get a handle on Entity Framework here and I am hitting some speed bumps... I have a Get() method that works fine and has been tested, but my Delete method is not working: public static void Delete(string name) { J1Entities db = new J1Entities(); db.DeleteObject(Get(name)); db.SaveChanges(); } But I get the following error: Error: The object cannot be deleted because it was not found in the ObjectStateManager. I ran the debugger, and the object inside the DeleteObject is correct...

ASP.NET MVC Search Page - Integer StartsWith On Linq + EF4

て烟熏妆下的殇ゞ 提交于 2019-12-30 05:35:13
问题 So, in my last post I was asking how to build a dynamic search filter using LINQ and EF4 (See Here) and finally came up with the solution of building the expression as a string and parse it to an expression using the Dynamic LINQ library. I that solved the problem. I was able to generate a Expression<Func<TSource, out bool>> and pass it to the Where() method of the DbSet . I am also trying to do this using MySql as a database behind EF4. The problem came when I tried to apply string

Reuseable ObjectContext or new ObjectContext for each set of operations?

拥有回忆 提交于 2019-12-30 01:31:12
问题 I'm new to the Entities Framework, and am just starting to play around with it in my free time. One of the major questions I have is regarding how to handle ObjectContexts. Which is generally preferred/recommended of these: This public class DataAccess{ MyDbContext m_Context; public DataAccess(){ m_Context = new MyDbContext(); } public IEnumerable<SomeItem> GetSomeItems(){ return m_Context.SomeItems; } public void DeleteSomeItem(SomeItem item){ m_Context.DeleteObject(item); m_Context

How do you implement Pipes and Filters pattern with LinqToSQL/Entity Framework/NHibernate?

半城伤御伤魂 提交于 2019-12-30 00:20:25
问题 While building by DAL Repository, I stumbled upon a concept called Pipes and Filters. I read about it here, here and saw a screencast from here. I am still not sure how to go about implementing this pattern. Theoretically all sounds good , but how do we really implement this in an enterprise scenario? I will appreciate, if you have any resources,tips or examples ro explanation for this pattern in context to the data mappers/ORM mentioned in the question. Thanks in advance!! 回答1: Ultimately,

How do you implement Pipes and Filters pattern with LinqToSQL/Entity Framework/NHibernate?

浪子不回头ぞ 提交于 2019-12-30 00:20:08
问题 While building by DAL Repository, I stumbled upon a concept called Pipes and Filters. I read about it here, here and saw a screencast from here. I am still not sure how to go about implementing this pattern. Theoretically all sounds good , but how do we really implement this in an enterprise scenario? I will appreciate, if you have any resources,tips or examples ro explanation for this pattern in context to the data mappers/ORM mentioned in the question. Thanks in advance!! 回答1: Ultimately,

The type or namespace name 'Objects' does not exist in the namespace 'System.Data'

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-29 11:32:34
问题 I am using entities, C# and SQL Server to create an n-tier app. I am creating some base classes common to all my DAL components. In this base class, i want to handle the connection state of the ObjectContext base class inherited by entities object. Compiling throws the following error: The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) Also, the using statement System.Data.Objects doesn't resolve for the same reason. I

Detect entities which have the same children

China☆狼群 提交于 2019-12-29 08:52:00
问题 I have two entities, Class and Student , linked in a many-to-many relationship. When data is imported from an external application, unfortunately some classes are created in duplicate. The 'duplicate' classes have different names, but the same subject and the same students. For example: { Id = 341, Title = '10rs/PE1a', SubjectId = 60, Students = { Jack, Bill, Sarah } } { Id = 429, Title = '10rs/PE1b', SubjectId = 60, Students = { Jack, Bill, Sarah } } There is no general rule for matching the

linq to entities, a where in where clause? (inner where)

这一生的挚爱 提交于 2019-12-29 05:18:08
问题 I have a table with a one to many mapping to a table that has a many to many mapping to another table. I'd like to do the following: var results = context.main_link_table .Where(l => l.some_table.RandomProperty == "myValue" && l.some_table.many_to_many_table .Where(m => m.RandomProperty == "myValue")); How can I achieve this? The first part will work but when trying it without the 'inner WHERE', I can't access the many_to_many_table's properties, but the "inner where" obviously won't compile.