entity-sql

Entity Framework & LINQ To SQL - Conflict of interest?

丶灬走出姿态 提交于 2019-12-31 09:29:28
问题 I've been reading on the blogosphere for the past week that Linq to SQL is dead [and long live EF and Linq to Entities]. But when I read the overview on MSDN, it appeared to me Linq to Entities generates eSQL just the way Linq to SQL generates SQL queries. Now, since the underlying implementation (and since SQL Server is not yet an ODBMS) is still a Relational store, at some point the Entity framework has to make the translation into SQL queries. Why not fix the Linq to SQL issues (m:m

In what scenarios would I need to use the CREATEREF, DEREF and REF keywords?

放肆的年华 提交于 2019-12-30 11:23:26
问题 This question is about why I would use the above keywords. I've found plenty of MSDN pages that explain how. I'm looking for the why. What query would I be trying to write that means I need them? I ask because the examples I have found appear to be achievable in other ways... To try and figure it out myself, I created a very simple entity model using the Employee and EmployeePayHistory tables from the AdventureWorks database. One example I saw online demonstrated something similar to the

Entity Framework 4.0 Entity SQL passing null ObjectParameter parameters

限于喜欢 提交于 2019-12-23 09:02:02
问题 I have an Entity SQL query: SELECT VALUE t FROM MyEntities AS t WHERE t.Name = @p OR (@p IS NULL AND t.Name IS NULL) I can execute the query as follows: var results = context.CreateQuery<WorkflowInstance>( query, new ObjectParameter("p", name)).ToList(); However, if the 'name' variable is null, then I get the System.ArgumentNullException. So I also tried to use DBNull.Value if the name was null, and I get the following exception: System.ArgumentOutOfRangeException was caught Message=The

How to String Concatenation in Entity SQL?

橙三吉。 提交于 2019-12-23 03:09:28
问题 A very quick question SQL: SELECT VALUE ROW( ('#' + CAST(pack.PackageID as Edm.String)) as PackageID) From ProductPackage It show error, edm.String not found, I also try String or Varchar,still error. I have read that reference but no help. http://msdn.microsoft.com/en-us/library/bb386905.aspx 回答1: It is a documentation problem. Try System.String instead of Edm.String . 来源: https://stackoverflow.com/questions/5323842/how-to-string-concatenation-in-entity-sql

Converting ESQL to LINQ to Entities. Sort by related entities

蹲街弑〆低调 提交于 2019-12-22 08:29:44
问题 I am using EF + RIA and unfortunately meet some problems with sorting by related entities. For such purpose there is ESQL query that I implemented (found only this solution): var queryESQL = string.Format( @" select VALUE ent from SomeEntities as ent join Attributes as ea ON ea.EntityId = ent.Id where ea.AttributeTypeId = @typeId order by ea.{0} {1}", columnName, descending ? "desc" : "asc"); var query = ObjectContext.CreateQuery<SomeEntity>(queryESQL, new ObjectParameter("typeId",

Comparing DateTime in Entity Framework with an Sql Server Compact database

风格不统一 提交于 2019-12-11 16:05:28
问题 Why this code throws a System.NotSupportedException telling that The specified method 'int? DateDiff(string, DateTime?, DateTime?)' on the type 'System.Data.Objects.SqlClient.SqlFunctions' cannot be translated into a LINQ to Entities store expression , though DateDiff has EdmFunction attribute? context.Users.Where(f => System.Data.Objects.SqlClient.SqlFunctions.DateDiff("second", f.LastLogOn, somedatetime) < 0) 回答1: Here is a complete enumeration of canonical Date and Time functions supported

Entity Sql for a Many to Many relationship

半腔热情 提交于 2019-12-11 01:25:14
问题 Consider two tables Bill and Product with a many to many relationship. How do you get all the bills for a particular product using Entity Sql? 回答1: You need to use some linq like this; ... using (YourEntities ye = new YourEntities()) { Product myProduct = ye.Product.First(p => p.ProductId = idParameter); var bills = myProduct.Bill.Load(); } ... This assumes that you have used the entitiy framework to build a model for you data. The bills variable will hold a collection of Bill objects that

Entity Framework 4.0: Entity SQL CAST Operation Not Working

≯℡__Kan透↙ 提交于 2019-12-10 07:27:18
问题 I'm trying to make a query where I cast a text column, which contains an integer as text, to an Int32. Here's the query: SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS Edm.Int32) > 5 However, I get an System.Data.EntitySqlException with the following message: Type 'Edm.Int32' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 1, column 75. According to MSDN, Edm.Int32 should be a valid type.

How to String Concatenation in Entity SQL?

空扰寡人 提交于 2019-12-08 18:21:26
A very quick question SQL: SELECT VALUE ROW( ('#' + CAST(pack.PackageID as Edm.String)) as PackageID) From ProductPackage It show error, edm.String not found, I also try String or Varchar,still error. I have read that reference but no help. http://msdn.microsoft.com/en-us/library/bb386905.aspx It is a documentation problem. Try System.String instead of Edm.String . 来源: https://stackoverflow.com/questions/5323842/how-to-string-concatenation-in-entity-sql

Entity Framework 4.0: Entity SQL CAST Operation Not Working

痴心易碎 提交于 2019-12-05 16:32:10
I'm trying to make a query where I cast a text column, which contains an integer as text, to an Int32. Here's the query: SELECT VALUE t FROM MyEntities AS t WHERE CAST(t.TextColumn AS Edm.Int32) > 5 However, I get an System.Data.EntitySqlException with the following message: Type 'Edm.Int32' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 1, column 75. According to MSDN , Edm.Int32 should be a valid type. Does anyone know what's wrong? Edit: After some trial and error, I found that the following works: