entity-framework-6

C# Generic Passing different objects with same properties

眉间皱痕 提交于 2019-11-29 15:43:57
I am not sure if what I am doing is possible. I have 2 methods. The body of the 2 methods are exactly identical, however the signature of the method both parameter and return are different. The passed in parameter's properties are changed and the object are different but have the same property name (They are two different Entity Framwork Entities). Inheriting both from a base object is not possible (i think) because these are Entity Framework Entities. Best to show example then talk about it.. Method 1 private static IQueryable<MapListing> ApplyMapFilterToListings(IQueryable<MapListing>

DbUpdateConcurrencyException using Entity Framework 6 with MySql

杀马特。学长 韩版系。学妹 提交于 2019-11-29 15:41:17
I'm having trouble with concurrency checks using EF6 and MySQL. The problem I'm having is that I get a concurrency exception thrown when I try to save data to the database. If you examine the sql that is output to the console it tries to query the concurrency field from the database using the old value in the where clause. Because this field has been updated by the database. Environment: Windows 7 64 bit Visual Studio 2013 Nuget packages installed: EF 6.0.1 MySql.ConnectorNET.Data 6.8.3.2 MySql.ConnectorNET.Entity 6.8.3.2 Demo Database SQL: DROP DATABASE IF EXISTS `bugreport`; CREATE DATABASE

Why is UserManager.CreateIdentityAsync() looking for IdentityRole and how to fix?

好久不见. 提交于 2019-11-29 14:26:24
问题 I'm using Identity2.0 with MVC5 CodeFirst I have extended both the IdentityUser and IdentityRole like this: public class ApplicationUser : IdentityUser { [Required] [StringLength(50)] public string FirstName { get; set; } [Required] [StringLength(50)] public string LastName { get; set; } } public class ApplicationRole : IdentityRole { [Required] [StringLength(50)] public string ProperName { get; set; } [Required] public string Description { get; set; } } public class MyAppDb :

entity framework 6 - check if record exists before insert and concurrency

北城余情 提交于 2019-11-29 14:04:53
I have the following scenario: A business logic function that uses ef6 checks if a record already exists. If the record does not exists, it is inserted on the database. Something like this if (!product.Skus.Any(s => s.SkuCodeGroup == productInfo.SkuCodeGroup && s.SkuCode == productInfo.SkuCode)) AddProductSku(); I have multiple threads calling this business logic function. What happens is: If the function is called simultaneous with the same parameters, both instances checks if the record exists - and it does not exists. So both instances inserts the same record. When context.SaveChanges() is

Using include doesn't change the behavior

烂漫一生 提交于 2019-11-29 13:57:14
Could Someone help me to clarify the difference between : var query = awlt.People.Include(p => p.EmailAddresses) .Where(p => p.LastName.Equals(lastName)) .SelectMany(a => a.EmailAddresses) .Select(a => a.EmailAddress1); var query = awlt.People .Where(p => p.LastName.Equals(lastName)) .SelectMany(a => a.EmailAddresses) .Select(a => a.EmailAddress1); I get the same results in both cases without knowing the difference . Does the Eager Loading require using Include ? The both query are retrieving the related data just first query by using Eager Loading (and yes Eager loading is achieved by use of

Storing a complex detached object graph in EF6

流过昼夜 提交于 2019-11-29 13:44:34
I have the current scenario: I'm using EF6 Code first, and have created a data-model something like this: public class MainObject{ ..some properties IList<SubObject> SubObjects{get;set;} } public class SubObject{ ..some properties IList<SubSubObject> SubSubObjects{get;set;} } public class SubObject{ ..some properties IList<SubObject> SubObjects{get;set;} } So basically I have a main object, that has 0 to many subobjects, and there is a many to many relationship between the subobject and the subsubobjects. I am creating a MVC application, so my normal program flow is that the user request a

Is it necessary to deploy the XML file in a class library?

早过忘川 提交于 2019-11-29 13:26:33
I have developed a lot of class library projects in VS 2012 to be used in Windows Forms and Web forms applications. The question is simple. Do I need to deploy the DLL file itself together with the XML file that is created? For example, the class library project is called DataWare. Upon building, I got 5 files in Release folder (this project reference Entity Framework): DataWare.dll DataWare.pdb DataWare.dll.config EntityFramework.dll EntityFramework.xml I know that ".pdb" file contains debugging information, so there is no need to deploy. The ".config" file is not taken into account. Instead

Is it possible to set a unique constraint using Entity Framework Code First?

夙愿已清 提交于 2019-11-29 13:07:04
I want to enforce Unique constraint in a table & I am using Entity Framework Code-First. Is it possible to add a unique constraint using EF 6 as i believe in earlier versions it was not possible. It appears that the unique constraint feature that was scheduled to release with Version 6 got pushed to 6.1. With EF 6.1, you can define a constraint using the Index attribute as shown below: [Index("IX_FirstAndSecond", 1, IsUnique = true)] public int FirstColumn { get; set; } [Index("IX_FirstAndSecond", 2, IsUnique = true)] public int SecondColumn { get; set; } OR You can use Fluent API as shown

How to set the one-to-one relationship with fluent api in this case? (EF6)

浪子不回头ぞ 提交于 2019-11-29 12:58:45
I have this two entities: public partial class Ficheros { public Guid Idfichero { get; set; } public long Iddocumento { get; set; } public byte[] Fichero { get; set; } public virtual Documentos IddocumentoNavigation { get; set; } } public partial class Documentos { public Documentos() { ElementosDocumentos = new HashSet<ElementosDocumentos>(); } public long Iddocumento { get; set; } public string Nombre { get; set; } public long? IdtipoDocumento { get; set; } public string Codigo { get; set; } public decimal? Espacio { get; set; } public string Unidades { get; set; } public long? Bytes { get;

Entity Framework 6: How to override SQL generator?

二次信任 提交于 2019-11-29 12:33:16
问题 I'd like to amend the SQL that's being generated by EF:CF when generating the database schema (DDL), as suggested by the Entity Framework team. How can this be done? I couldn't find anything appropriate via Google. 回答1: You can override the MigrationSqlGenerator that is used by Entity Framework by calling the DbMigrationsConfiguration.SetSqlGenerator() method in the constructor of your DbMigrationsConfiguration class, passing the database provider name (e.g. "System.Data.SqlClient" for SQL