entity-framework

Using ASP.NET Identity on MVC 5 project but httpcontext User.ProviderName is “AspNetSqlRoleProvider”

情到浓时终转凉″ 提交于 2020-01-11 05:45:08
问题 I have a MVC 5 project using ASP.NET Identity (Invidual user account). As Database ORM I am using Entity framework 6 and IoC is taken care by Ninject. Solution structure is following MVC project -- has my controllers, views and ninject setup. For Ninject I got Ninject.MVC3 from nuget. Data project --- has my DataContext (IdentityDbContext) and my ApplicationUser (IdentityUser). My Data services and all repositories Core project -- has all my entities and interfaces [Authorize] attribute works

EF6 alpha Async Await on an Entity Stored Procedure / Function Import?

五迷三道 提交于 2020-01-11 05:38:09
问题 I'd like to apply the new async await functionality to Stored Procedures / Function Imports imported in my Entity model, but have as yet been unable to with the EF6 alpha. Is it yet possible in EF6 alpha2 (or the nightly build as of 20211) to call any of the new Async methods on an Entity Function Import (which calls a SQL Stored Procedure) that returns a collection of Complex Type? e.g. private async Task<IList<Company>> getInfo (string id) { using (CustomEntity context = new CustomEntity())

Entity framework Invalid Column name, EF adds numer 1 to primary key

旧街凉风 提交于 2020-01-11 04:50:06
问题 I have these two entities: public partial class Suscriptores { public Suscriptores() { this.Publicacion = new HashSet<Publicacion>(); } [Key] public int IdSuscriptor { get; set; } public string LogoSuscriptor { get; set; } public string Identificacion { get; set; } public string Nombre { get; set; } public string Direccion { get; set; } public string Telefono { get; set; } public string Email { get; set; } public string Fax { get; set; } public string Home { get; set; } public virtual

How to make all entities access:internal instead of public in EDMX?

♀尐吖头ヾ 提交于 2020-01-11 04:42:07
问题 I'd like my Entity Framework model to generate entities with internal access modifier, instead of public . I use the EF model in a library and I want only a single class (some controller) to be accessible from outside. Is there any simple way to make the EF model generation use internal modifer instead of public , including model regeneration on update? 回答1: It's very much like the anwer I got on a similar question. But in your case you want to customize the access modifier of the classes,

Querying SQL Server xml column with user provided XPath via Entity Framework

試著忘記壹切 提交于 2020-01-11 02:49:15
问题 I'm having a really tough time figuring how to use an xml data column in SQL Server, specifically for use with Entity Framework. Basically, one of our tables stores "custom metadata" provided by users in the form of XML, so it seemed sensible to store this in an Xml column in the table. One of the requirements of our application is to support searching of the metadata, however. The users are able to provided an XPath query string, as well as a value to compare the value of the XPath with, to

One or Zero to One Entity Framework Code First FluentApi

梦想的初衷 提交于 2020-01-11 02:08:53
问题 I need to create fluentapi one or zero to one reference and have navigation properties on both of entities. EntityTwo should contain simple proerty to store foreign key (EntityOneId) public class EntityOne { public int Id { get; set; } public EntityTwo EntityTwo { get; set; } } public class EntityTwo { public int Id { get; set; } public int EntityOneId { get; set; } public EntityOne EntityOne { get; set; } } public class MyDbContext : DbContext { protected override void OnModelCreating

Entity Framework 6: is there a way to iterate through a table without holding each row in memory

牧云@^-^@ 提交于 2020-01-11 02:06:46
问题 I would like to be able to iterate through every row in an entity table without holding every row in memory. This is a read only operation and every row can be discarded after being processed. If there is a way to discard the row after processing that would be fine. I know that this can be achieved using a DataReader (which is outside the scope of EF), but can it be achieved within EF? Or is there a way to obtain a DataReader from within EF without directly using SQL? More detailed example:

Does the Entity Framework have an equivalent of DataContext.GetTable<TEntity> from Linq2Sql (ObjectContext.CreateQuery<T>?)

一笑奈何 提交于 2020-01-11 02:02:32
问题 I'm looking for an equivalent of the DataContext.GetTable<TEntity> in Entity Framework. I've found the ObjectContext.CreateQuery<T> method but it is different from DataContext.GetTable<TEntity> since it needs a querystring to work. Is there a way to get an IQueryable object for a table using the entity type without specifying the querystring? *EDIT: Added code snippet* This is a snippet of a Repository class I've implemented that works with linq2sql. I can't use ObjectContext.[TableName]

Referential Integrity Constraint violation when attempting to set a FK to null

你离开我真会死。 提交于 2020-01-11 01:49:45
问题 I am trying to update an entity in EF6. I have read that if I wish to change a ForeignKey property, I have to then ensure the Navigation Property is the correct one, or set it to null. I have taken the set to null approach, but I still receive the Referential Integrity Constraint Exception: A referential integrity constraint violation occurred: The property value(s) of 'Contact.idContact' on one end of a relationship do not match the property value(s) of 'Entity.id_EntityContactInfo' on the

AddOrUpdate works not as expected and produces duplicates

喜欢而已 提交于 2020-01-10 21:20:27
问题 I'm using Code-First DBContext-based EF5 setup. In DbMigrationsConfiguration.Seed I'm trying to fill DB with default dummy data. To accomplish this task, I use DbSet.AddOrUpdate method. The simplest code to illustrate my aim: j = 0; var cities = new[] { "Berlin", "Vienna", "London", "Bristol", "Rome", "Stockholm", "Oslo", "Helsinki", "Amsterdam", "Dublin" }; var cityObjects = new City[cities.Length]; foreach (string c in cities) { int id = r.NextDouble() > 0.5 ? 0 : 1; var city = new City {