entity-framework-4

Entity framework self referencing loop detected [duplicate]

独自空忆成欢 提交于 2019-12-17 02:27:04
问题 This question already has answers here : JSON.NET Error Self referencing loop detected for type (21 answers) Closed yesterday . I have a strange error. I'm experimenting with a .NET 4.5 Web API, Entity Framework and MS SQL Server. I've already created the database and set up the correct primary and foreign keys and relationships. I've created a .edmx model and imported two tables: Employee and Department. A department can have many employees and this relationship exists. I created a new

EF4 - The selected stored procedure returns no columns

我怕爱的太早我们不能终老 提交于 2019-12-17 02:11:56
问题 I have query in a stored procedure that calls some linked servers with some dynamic SQL. I understand that EF doesn't like that, so I specifically listed all the columns that would be returned. Yet, it still doesn't like that. What am I doing wrong here? I just want EF to be able to detect the columns returned from the stored procedure so I can create the classes I need. Please see the following code that makes up the last lines of my stored procedure: SELECT #TempMain.ID, #TempMain.Class

EF4 - The selected stored procedure returns no columns

泄露秘密 提交于 2019-12-17 02:11:14
问题 I have query in a stored procedure that calls some linked servers with some dynamic SQL. I understand that EF doesn't like that, so I specifically listed all the columns that would be returned. Yet, it still doesn't like that. What am I doing wrong here? I just want EF to be able to detect the columns returned from the stored procedure so I can create the classes I need. Please see the following code that makes up the last lines of my stored procedure: SELECT #TempMain.ID, #TempMain.Class

LINQ to Entities case sensitive comparison

穿精又带淫゛_ 提交于 2019-12-16 20:14:05
问题 This isn't a case-sensitive comparison in LINQ to Entities: Thingies.First(t => t.Name == "ThingamaBob"); How can I achieve case sensitive comparison with LINQ to Entities? 回答1: That's because you are using LINQ To Entities which is ultimately convert your Lambda expressions into SQL statements. That means the case sensitivity is at the mercy of your SQL Server which by default has SQL_Latin1_General_CP1_CI_AS Collation and that is NOT case sensitive. Using ObjectQuery.ToTraceString to see

Is it possible to define error message for UNIQUE KEY constraint in SQL SERVER when it is called by EF 4.0?

六月ゝ 毕业季﹏ 提交于 2019-12-14 03:58:15
问题 I don't need to execute duplicatation query like checking some column is unique or not because this operation always execute with SQL Server constraint. However, default error message from SQL Server is not well-defined for end-user. Do you have any idea for change/redefine error message to be more user-friendly? PS. I execute all query via Entity Framework 4.0. 回答1: The only way I know to do this is to catch SqlException and then check the Number property. This property is a short-cut to the

Ordering Column Attributes in Entity Framework

旧街凉风 提交于 2019-12-14 03:45:20
问题 I am using Entity Framework in my application,so I have mapped my property objects to database objects. The property objects have been defined using Column attribute. Now,I want to order them,but I can't find the property in Column Attribute for Order. I have included System.ComponentModel.DataAnnotations,but still not getting it Thanks in advance 回答1: just use : using System.ComponentModel.DataAnnotations.Schema; Code : [Column("Name" , Order = 1)] public int UserName { get; set; } Notice :

EF 4.0 / Weird behaviour of FirstOrDefault method

浪尽此生 提交于 2019-12-14 03:39:52
问题 I am developing a small application using EF 4.0 and POCO. While testing my application, I grew concerned about the performance of the Data Access Layer. So I fired SQL Profiler to see that when trying to retrieve a record: ctx.Orders.Include("OrderItems").FirstOrDefault<Order>(c => c.OrderID == id); the EF issues a SQL statement that would retrieve all records from the Orders table on the Server and as such return to DAL at which time L2E would pick one thay meet the criteria and return it.

c# List<string> to Lambda Expression with starter example: Refactor to handle the List

橙三吉。 提交于 2019-12-14 03:29:03
问题 I have this: List<string> fields; fields[0] = "firstFieldName"; fields[1] = "secondFieldName"; ... fields[n] = "nthFieldName"; I want to get this: var selector = p => new {p.firstField, p.secondField, ..., p.nthFieldName} // selector is of type Expression<Func<Entity, object>> GoofBallLogic had this code that was simliar, ending up with p => p.column // Entity is an object in a diagram from Entity Framework 4 var p = Expression.Parameter(typeof(Entity, "p"); var selector = Expression.Lambda

C#/ASP.NET lambda conversion

时光怂恿深爱的人放手 提交于 2019-12-14 03:27:29
问题 Somehow when I return this to my view: return View(db.Properties.ToList()); I get 3 properties, one of which has the location value of "Oregon". But in another method declared like this: public ViewResult Browse(string location) { return View(db.Properties.Where(p => p.location == location).ToList()); } I get 0 properties. I suspect the string "location" is getting converted to something strange somewhere, but I'm not sure in what way it would be getting converted. When I replace the lambda '

An object with a key that matches the key of the supplied object could not be found in the ObjectStateManager

…衆ロ難τιáo~ 提交于 2019-12-14 03:19:01
问题 I want to update record from FormView with ObjectDataSource and lose my day to solve this error. An object with a key that matches the key of the supplied object could not be found in the ObjectStateManager. Verify that the key values of the supplied object match the key values of the object to which changes must be applied. My code is below private static Entities1 _db = null; public static Entities1 CreateDataContext() { if (_db == null) { _db = new Entities1(System.Configuration