entity-framework-5

Entity Framework Exception: Ambiguous match found

你离开我真会死。 提交于 2019-12-01 17:45:11
I get the error: Ambiguous match found During this code on the .Add var db = new NexusEntities(); db.Reports.Add(mmr); From googling it appears to be an issue if the there are two classes with the same name but in different namespaces. As far as I can tell this is not the case... Is there another reason why this error can happen? Or is there a way to tell which parameter it is finding two of? This is a "weakness" in EF. It happens when the same property appears in class / subtype hierarchy. Most likely you have a hidden field. i.e. a property that has been redefined. When EF looks for the a

Could not determine storage version - Entity Framework

妖精的绣舞 提交于 2019-12-01 17:42:01
问题 I'm implementing code first pattern in a separate project in my current solution. Since I did this and I initialize my connection string in DbContext I get this weird error: Could not determine storage version; a valid storage connection or a version hint is required. I'm using Entity Framework 5.0.0.0 and the rest of my solutions projects work great as they use EDMX files for database access yet only my code first project throws this exception. What is it and why? 回答1: Solved the same issue

The INSERT statement conflicted with the FOREIGN KEY constraint error

…衆ロ難τιáo~ 提交于 2019-12-01 16:41:32
问题 Hi I'm getting this error The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUsers_dbo.Contacts_ContactID". The conflict occurred in database "aspnet-COGMakati-20140119015553", table "dbo.Contacts", column 'ContactID'. The statement has been terminated. I'm using Entity Framework and MVC 5's IdentityUser so I'm really lost on what I'm doing :| This is what I'm trying to populate: public class User : IdentityUser { [Required] [Display(Name = "First Name")] public

Entity Framework 5 : Proper method to replace entry in context

五迷三道 提交于 2019-12-01 16:16:00
What i want to do is simple. I have a list of parts in the db, and i want to delete/insert/update them according to an update list. The main issue is that, when i want to replace an entry i can't attach it to the context because the older(to be updated) entry is already attached (by previous read call) and an exception is thrown. I came around with 3 thoughts. Manually Detach the old entry and attach the new one (although changing entity state to detached still throws exception) Manually change the values of the old entry with the new ones Make the read call non track able (AsNoTracking()),

Entity Framework with optional parameters?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 16:05:42
问题 Using Entity Framework 5 is it possible to use a stored proc with optional parameters such that you do not have to add a null for each unused parameter? The stored proc I have to use has 87 parameters only 2 of which are required. I really hate the idea of having to put 85 nulls in each call. 回答1: You can use ObjectContext.ExecuteFunction method ( DbContext is a wrapper over ObjectContext ) to execute some stored procedure and pass list of parameters: FooEntities db = new FooEntities(); var

ActionFilterAttribute ninject injection - DbContext has been disposed

会有一股神秘感。 提交于 2019-12-01 15:57:50
问题 I have my project which uses the usual Repository pattern with Services and Unit of Work (all with Ninject injecting the dependencies from a NinjectModule), but I'm trying to access a service from an ActionFilterAttribute to inject some information (from DB) in the layout of the pages I show so I don't need to mess with all the actions on each controller. The problem comes when I save to DB on one screen and move to the next and then come back to the previous (with a standard @Url.Action ):

Required Properties on optional Entity Framework Complex Types

自作多情 提交于 2019-12-01 14:31:21
问题 I want to define [Required] attributes on a Complex Type in Entity Framework. For example, I have a Customer entity with an optional Address . The Address entity has a required PostCode property. [ComplexType] public class Address { public string Address1 { get; set; } [Required] public string PostCode { get; set; } } public class Customer { public int CustomerId {get;set;} public Address Address {get;set;} } I do NOT want to store my Complex type as a separate entity (I'm not actually using

Using stored procedure in Entity Framework 5 with complex type?

﹥>﹥吖頭↗ 提交于 2019-12-01 14:07:12
I have the following stored procedure in SQL Server: ALTER PROCEDURE [dbo].[FullTextSearchOnContent] ( @SearchText NVARCHAR(200), @LanguageId INT , @ContentStatusId INT , @ResultCount INT ) AS BEGIN SET FMTONLY OFF; SET NOCOUNT ON; IF (@SearchText IS NULL) OR (@SearchText = '') OR (@ResultCount IS NULL) OR (@ResultCount = 0) RETURN NULL; SELECT DISTINCT TOP(@ResultCount) C.Id AS ContentId, C.ImagePath AS ContentImagePath, C.IsSpecial,C.LanguageId,C.LockCommenting,C.RegistrationDate AS ContentRegistrationDate,C.StatusId AS ContentStatusId,C.Summary,C.Title,C.VisitNumber,C.AllTagsString, CS

Entity Framework - what is the current command timeout value

南笙酒味 提交于 2019-12-01 13:45:45
问题 I am using Entity Framework 5 and I wish to know the command timeout value. In order to do so, I cast the dbContext object to an ObjectContext and I access the CommandTimeout property. int ? currentCommandTimeout = ((IObjectContextAdapter)dbContext).ObjectContext.CommandTimeout; The current value of this property is null which means that the current command timeout is the default value of the underlying provider. Who is the underlying provider? How can I read (via EF code) the current command

I do not understand how EF5 dbContext.Entry(entity).Reload() method is supposed to work?

若如初见. 提交于 2019-12-01 13:15:44
In this example : using System; using System.Collections.Generic; using dbModel; using System.Linq; using System.Data.Entity.Infrastructure; namespace WinApp { public partial class Form1 : Form { private dbEntities dbc; public IQueryable<ARTIKLI> art; public IQueryable<ART_GRUPE> grp; public Form1() { InitializeComponent(); dbc = new dbEntities(); } private void GetData() { art = from a in dbc.ARTIKLIs select a; grp = from g in dbc.ART_GRUPE select g; artikliBindingSource.DataSource = art.ToList(); artGrupeBindingSource.DataSource = grp.ToList(); } private void Form1_FormClosing(object sender,