entity-framework-4

Setup EF4 data source for SQL Compact 4

走远了吗. 提交于 2019-12-22 04:03:06
问题 I've installed visual studio 2010 SP1, EF 4.1, SQL Compact 4.0 with vs tools. Everything is appears ok, except I can't use SQL Compact 4 as a data source for Entity framework through the wizard. The only alternative is SQL Compact 3.5. Is there a patch or something I'm missing? Has anyone got EF 4 and SQL Compact 4.0 working together without hacking everything. 回答1: No you're not missing something. In VS2010SP1 SQLCE40 is supported only in web projects. You can get 4.0 EDM support with SQL

How do I save multiple Models edited in form in ASP.NET MVC?

有些话、适合烂在心里 提交于 2019-12-22 00:44:42
问题 I need to make a view which will support bulk inserting of objects. I am using the repository pattern with Entity Framework 4. Since there will be multiple individual models in the View, how do I handle binding the view's model to what get's sent to the Repository? How do I retreive the input values from the form into the controller? I have managed to do the view but I am unable to retrieve the data from controller. I used the folowing statement but after the post it heppens to be nul public

How do you centralize the Entity Framework data context in a web application?

走远了吗. 提交于 2019-12-22 00:35:42
问题 In our application we use the repository pattern to retrieve and persist data from our data storage medium. The medium we opted to use is Entity Framework 4. This seems to be a very clean way to do things and has worked great 99% of the time. Now we are encountering an issue. We have two repositories, like this: public class UserRepository : IUserRepository { Entities dataContext = new Entities(); public User GetUser(string username) { return dataContext.Users.SingleOrDefault(x => x.Username

EF: Cross edmx (same DB) linq-to-entites query

家住魔仙堡 提交于 2019-12-22 00:24:51
问题 How can I use two EDMXs, in separate assemblies, yet above the SAME database, to create a linq-to-entities query that uses them both? E.g. This is what I am trying to do: using (var context1 = new Entities1()) { using (var context2 = new Entities2()) { var items2 = context2.Items.Where(item2 => item2.Color == "Red"); var query = context1.Items.Where(item => items2.Any(item2 => item2.PainterId == item.PainterId)); } } > This results in NotSupportedException. Message: "The specified LINQ

Add object and its relationships atomically in SQL Server database

狂风中的少年 提交于 2019-12-21 23:26:12
问题 Suppose I want to insert a new Experiment in my SQL Server database, using Entity framework 4.0: Experiment has 1..* Tasks in it Both Experiment and Task derive from EntityObject Also, there is a database constraint that each Task must have exactly one "parent" Experiment linked to it Insertion must be atomic. What I mean by atomic is that a reader on database must never be able to read an Experiment which is not fully written to database, for instance an Experiment with no Task . All

How can I create an ObjectContext from separate ssdl + csdl + msl files and no edmx?

三世轮回 提交于 2019-12-21 23:06:04
问题 Given: An empty C# project 3 loose files: an SSDL, CSDL and a MSL (generated elsewhere) No EDMX file What modifications/additions should I perform on project to compile these files into a T4-based ObjectContext (e.g. using POCOs T4 generators)... if I already have all classes generated for entities? if I have no classes generated for entities? Would it be easier to generate the ObjectContext and or classes if I first combine the files into an EDMX with no Designer section? 回答1: Working

ASP.NET MVC3 and Entity Framework v4.1 with error An entity object cannot be referenced by multiple instances of IEntityChangeTracker

删除回忆录丶 提交于 2019-12-21 23:03:13
问题 Currently when adding a product to my cart the Add action of my CartController is called with the orderEntryDisplayViewModel (the order line object). [HttpPost] public RedirectToRouteResult Add(Cart cart, OrderEntryDisplayViewModel orderLine) { if (!ModelState.IsValid) { return RedirectToAction("Display", "OrderEntry", new { Product = orderLine.Line.PartNum }); } CompleteProduct product = null; orderLine.Line.RequestedShipDate = orderLine.RequestedShipDate; if (orderLine.Line.NewMyPartNum !=

What could be causing slow function import performance?

浪子不回头ぞ 提交于 2019-12-21 22:22:12
问题 I have a stored procedure that finishes execution after a few ms when I run it by itself. However, once I import the stored procedure into EF and call it with the same exact parameters, it takes like 5 minutes to finish. Is there some kind of setting I need to tweak or what is causing this slowness? 回答1: I've seen people have this issue when SQL Server has a bad cached execution plan. People seem to recommend running the following commands to fix it: DBCC DROPCLEANBUFFERS DBCC FREEPROCCACHE

How to use Entity Framework context with dependency injection?

偶尔善良 提交于 2019-12-21 22:04:14
问题 I'm trying to setup a base Repository class that can use the Entity Framework edmx model context. The problem I'm having is that I need to find an interface that the EF EDMX object context implements so I can pass to the constructor via dependency injections. I've got around this before by using a DataFactory that creates it and stores it in the HttpContext but that kills the ability to unit test. Any help would be appreciated. Thanks! public abstract class BaseRepository<T> where T :

How to make conversion SQL Inner joins query vs Entity Framework

a 夏天 提交于 2019-12-21 21:41:34
问题 Here are three tables Service_Orders, Project_Services and Company. There is inner join between 3 tables by Service Order and CompanyID. I want below query to convert into Entity framework with Lambda Express using C# or Vb.net. select top 10 * from [Service_Orders] a,[Project_Services] b,[Company] c where a.so_no = b.service_order and c.companyId = b.compid 回答1: Lambda syntax: var query = db.Service_Orders .Join(db.Project_Services, a => a.so_no equals, b => b.service_order, (a,b) => new { a