entity-framework-4

MVC 4, EF 4.3 Managing context during the lifecycle of an Application Request

寵の児 提交于 2019-12-11 08:17:09
问题 Situation: What I'd like to do is have access to the data context for the life cycle of a page. This is primarily to (a) avoid series of using() and to avoid (b) out of scope exceptions in the view when a lazy loaded property is accessed. Edit: I'm using MVC 4 and Entity Framework 4.3.1 (the latest) What I typically do is using (MyDB b = new MyDB()) { ...do all my stuff } In my controller or the data layer. The nice thing about this, based on my reading, is it's clean, causes no memory leaks

Cannot perform an ORDERBY against my EF4 data

老子叫甜甜 提交于 2019-12-11 08:15:02
问题 I have a query hitting EF4 using STEs and I'm having an issue with user-defined sorting. In debugging this, I have removed the dynamic sorting and am hard-coding it and I still have the issue. If I swap/uncomment the var results = xxx lines in GetMyBusinesses() , my results are not sorted any differently - they are always sorting it ascendingly. FYI, Name is a varchar(200) field in SQL 2008 on my Business table. private IQueryable<Business> GetMyBusinesses(MyDBContext CurrentContext) { var

Format List<T> to concatenate fields

浪子不回头ぞ 提交于 2019-12-11 07:59:56
问题 I've looked at hundreds of similar questions on SO to the one asked, but haven't found my answer. If this has been asked before, please accept my apologies. I have a SQL database with a column of cities and a column of their states respectively. I use the Entity Framework as my DAL and in my BLL have lots of LINQ to format, move stuff, etc. I have on my UI a drop-down which currently accepts a ToList() from a method in my BLL and all works well, but I need to alter this method to return city

Reference a parent table for a Navigation Property in EF

半城伤御伤魂 提交于 2019-12-11 07:55:20
问题 I essentially have three tables with FK's Make MakeId MakeName Model ModelId ModelName MakeId (FK) Vehicle VehicleId DatePurchased ModelId (FK) I would like a navigation property from Vehicle to Make without modifying my database I tried: public class Make { public int MakeId {get;set;} <snip>...</snip> public virtual Vehicle Vehicles {get;set;} } <snip>Model</snip> public class Vehicle { public int VehicleId {get;set} <snip>...</snip> public virtual Make VehicleMake {get;set;} } public class

How to create multiple Left Join in Entity framework

笑着哭i 提交于 2019-12-11 07:49:01
问题 I have sql query: FROM tbl_UploadFile AS AllFiles LEFT JOIN tbl_FirstFile AS firstFiles ON AllFiles.Guid=firstFiles.[FileId] LEFT JOIN tbl_SecondFile AS secondFiles ON AllFiles.Guid=secondFiles.[FileId] LEFT JOIN tbl_ThirdFile AS thirdFiles ON AllFiles.Guid=thirdFiles.[FileId] WHERE firstFiles.[FileId] is NULL AND secondFiles.[FileId] is NULL AND thirdFiles.[FileId] is NULL; This query return guid from tbl_UploadFile, if this guid doen't use on tbl_FirstFile, tbl_SecondFile and tbl_ThirdFile.

SQL to Linq query with multiple left outer joins

与世无争的帅哥 提交于 2019-12-11 07:41:47
问题 I'm trying to convert an SQL query to Linq containing several left outer joins, but I'm encountering an odd situation. The relevant part of my SQL is: SELECT * FROM dbo.SessionDetails as sd left outer join dbo.VoipDetails as vd on vd.SessionIdTime = sd.SessionIdTime and vd.SessionIdSeq = sd.SessionIdSeq left outer join dbo.Gateways as fgw on vd.FromGatewayId = fgw.GatewayId My Linq query so far is: var query = from sd in dbo.SessionDetails join vd in dbo.VoipDetails on new { sd.SessionIdTime,

How to check against a database for a specific entry using entity framework

不问归期 提交于 2019-12-11 07:39:49
问题 I am creating a login screen where I get the user Id and password from the form .How do I use the entity framework to check if a duplicate id already exists in the database ? I am using entity framework 4 and asp.net 4.0 I am really new to the entity framework so a simple response would be very helpful. Thanks ! 回答1: Duplicate id? So do you want to validate that login is correct or do you want to check that login already exists during creating a new user? If you want to validate login use:

SQL Server foreign keys messing with entity framework model

筅森魡賤 提交于 2019-12-11 07:28:53
问题 I have an entity framework model, and I noticed that one table, a usergroup table is missing from the diagrams in the model file. This meant I could not modify it from the standard SQL calls to become part of the entity framework (i.e., to make a class file for it with entities). I can see it under "entity sets" but not in the diagram. Every time I try to add, it doesn't show it as an option to add in the "update model" menu. So I deleted it from Entity set, and then I finally saw it in

Problem using SQL Server CE with Entity Framework code-first and ASP.NET MVC 3 and mvc miniprofiler

末鹿安然 提交于 2019-12-11 07:27:31
问题 I am attempting to create an ASP.NET MVC 3 application using C#, Entity Framework 4.0 code-first and SQL Server CE, and the automated scaffolding. Everything works fine until I try to actually use a page that connects to the SQL Server CE database. My connection in the web.config is this <add name="BRX" connectionString="Data Source=|DataDirectory|BRX.sdf" providerName="System.Data.SqlServerCe.4.0"/> My model class looks like this using System; using System.Collections.Generic; using System

Unobtrusive validation fails when a Checkbox is on the form

青春壹個敷衍的年華 提交于 2019-12-11 07:23:53
问题 I have a simple Login page that suddenly (After upgrading Jquery.js and Jquery-ui.js to 1.10.2 and 1.10.3 respectively) started to actually reach the action result instead of showing the client side validation messages defined on the E.F Data Annotations. So I found out that removing the only CheckBoxFor that I have besides the User and Password, the submit button actually works as it should be so that it raises client validations only without reaching the controller. Any reason for this