entity-framework-5

EF vs Nhibernate Merge Disconnected Object Graph

两盒软妹~` 提交于 2019-12-05 09:46:20
I just started a new project a few weeks ago and decided to give EF Code First a try, I used NHIbernate before and i loved the idea of having an ORM out-of-the-bow from MS, and so far it's been great - until i started making complex objects. My project tiers are as follows: Azure WCF Role - to handle the DAL with EF Code First. Azure WebSite Role with MVC 4 with Knockout - to deal with the client. (I created the WCFRole for the future where we'll need access to the service from different platforms) Here is the very basic EF Code First design that i'm having trouble with: -I'm transferring only

Any workaround for lack of support for PadLeft in EF5.x?

最后都变了- 提交于 2019-12-05 08:38:38
I'm working on an app in MVC4 and Entity Framework 5 and recently came across this exception when executing my query. {"LINQ to Entities does not recognize the method 'System.String PadLeft(Int32, Char)' method, and this method cannot be translated into a store expression."} When I have run across similar errors in the past, I've just made a variable outside the query and then used the variable in the LINQ statement. Unfortunately, in this case I'm manipulating the row results so I'm not sure how to go about that or if that is the best method. Any help would be appreciated. My query is below:

Entity Framework DB First: Timestamp column not working

て烟熏妆下的殇ゞ 提交于 2019-12-05 08:35:20
Using db first approach, I want my application to throw a concurrency exception whenever I try to update an (out-of-date) entity which it's correspoinding row in the database has been already updated by another application/user/session. I am using Entity Framework 5 on .Net 4.5. The corresponding table has a Timestamp column to maintain row version. I have done this in the past by adding a timestamp field to the table you wish to perform a concurrency check. (in my example i added a column called ConcurrencyCheck) There are two types of concurrency mode here depending on your needs : 1

POCO Class in EF not working as Expected

给你一囗甜甜゛ 提交于 2019-12-05 07:24:47
I have created a DataBase in SQL and created an EDMX in Visual Studio 2012. It automatically created POCO (TT) classes. Everything looks fine. Now I change the column name of a table. I update the EDMX. Opening the EDMX in XML and everything looks fine. Question 1 After I ran Custom tool in TT, I see that a new property got created additionally, e.g.: SQL table name : Student Column name : sName In my POCO Class public int sName{ get; set; } got automatically created. Now I change the column name in SQL to Column name : studentName My POCO class public int sName{ get; set; } public int

Visual Studio 2012 Code First still uses SQLEXPRESS by default

心不动则不痛 提交于 2019-12-05 06:12:31
I created a brand new Web API project, created a simple Code First model (one class with an id and the dbcontext object, and that's it), and ran Enable-Migrations in the package manager console. I noticed that it creates the database in SQLEXPRESS rather than LocalDB, despite the DefaultConnection string pointing to (LocalDB) in the Web.config file. This causes subsequent queries to fail, claiming that the database hasn't been initialized. How do I get the Enable-Migrations command in VS 2012 to point to LocalDB rather than SQLExpress? I've tried installing SQL Management Studio 2012 Express

Retaining Form Values After Post (not part of model)

时间秒杀一切 提交于 2019-12-05 06:05:46
I have a MVC4 page that has a form with a collection of checkboxes, radio buttons and textboxes used as the search fields. Upon post the selections are parsed and the lower results grid is updated with new results. Right now all the form values are wiped out upon return and the new results are displayed in the grid - only the grid is part of the model. I want all the form selections to retain their values after post so the user can see (and change) the selections for next post/search. The form is popuplated with viewbags. @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { id =

Entity Framework Skip method running very slow

与世无争的帅哥 提交于 2019-12-05 05:56:58
I'm using Entity Framework 5, ObjectContext and POCOs on my data access layer. I have a generic respository implementation and I have a method that queries the database with paging using Skip() and Take(). Everything works fine, except that the query performance is very slow when skipping a lot of rows (I'm talking about 170k rows) This is an excerpt of my query on Linq to Entities: C# Code: ObjectContext oc = TheOBJEntitiesFactory.CreateOBJEntitiesContext(connection); var idPred = oc.CreateObjectSet<view_Trans>("view_Trans").AsQueryable(); idPred = idPred.OrderBy(sortColumn, sortDirection

Selectively Disabling Cascade Delete on Many-to-Many Link Table

你。 提交于 2019-12-05 05:47:15
Is it possible to selectively remove the Cascade Delete option on an automatically-generated many-to-many link table in Entity Framework 5 Code First? Here's a simple example which needs it: public class Parent { public int Id { get; set; } public virtual IList<ChildA> As { get; set; } public virtual IList<ChildB> Bs { get; set; } } public class ChildA { public int Id { get; set; } [Required] public virtual Parent Parent { get; set; } public virtual IList<ChildB> ChildBJoins { get; set; } } public class ChildB { public int Id { get; set; } [Required] public virtual Parent Parent { get; set; }

“EntityType has no key defined” exception although key is defined with HasKey

孤街浪徒 提交于 2019-12-05 05:35:23
Using EF 5 (reverse engineered code first), my model was working fine until it suddenly stopped. \tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ProjectsDate' has no key defined. Define the key for this EntityType. \tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ProjectsRisk' has no key defined. Define the key for this EntityType. I define a key using fluent API rather than attributes, here is my ProjectsDates classes. public partial class ProjectsDate { public string OSProjectCode { get; set; } public Nullable<System.DateTime> TargetStart { get; set; } public Nullable<System

Entity Framework doesn't query derived classes - Error in DbOfTypeExpression

China☆狼群 提交于 2019-12-05 05:16:48
I have a base class and two derived classes. Each of the derived classes implements the same type as a property - the only difference is the property name. Sadly I don't have much influence on the class design -> they have been generated from a wsdl file. I then have a property on the BaseType to encapsulate the common property. The plan was to use this property in my web views etc. I have used the famous "Fruit-Example" to demonstrate the problem: public class FruitBase { public virtual int ID { get; set; } // // The plan is to use this property in mvc view // [NotMapped] public virtual