entity-framework-6

asp.net mvc 5 entity framework 6 identity working with trust level = medium?

萝らか妹 提交于 2019-12-04 06:38:29
问题 Creating the simplest project (In visual studio 2013 -> asp.net web application -> MVC authentication with individual accounts), it works perfectly on localhost. However, when sending to the server (medium trust level), the project does not work when I try to enter login. See the error image: http://s18.postimg.org/fm2qw8gzt/print.png I tried to include on assembly.cs [assembly: AllowPartiallyTrustedCallers]. It did not work. I have created a strong name key. It did not work. The server does

Determining the range of value for a field in database by using db-migration

点点圈 提交于 2019-12-04 06:13:55
问题 I've used Entity Framework 6.x and I've produced my database by code-first approach. After creating db, I've decided to some changes in my db. for example I want to determine a range of value for Size property in my model. my model: public class Tag : Entity, ITag { /// <summary> /// Size can be 1, 2, 3 or 4 /// </summary> [Range(1, 4)] public virtual int Size { get; set; } [Required] [StringLength(25)] public virtual string Title { get; set; } [StringLength(256)] public virtual string

Get selected values after joining multiple tables in Entity Framework 6 using Lambda

送分小仙女□ 提交于 2019-12-04 05:49:02
问题 I have three tables ( simplified example for this issue ): Models are generated using EntityFramework Database-First approach. OwnerModel public partial class Owner { public Owner() { this.OwnerDogMapper= new HashSet<OwnerDogMapper>(); } public string OwnerId { get; set; } public string OwnerName { get; set; } public virtual ICollection<OwnerDogMapper> OwnerDogMapper{ get; set; } } DogTable public partial class Dog { public Dog() { this.OwnerDogMapper= new HashSet<OwnerDogMapper>(); } public

Entity Framework 6: Disable Lazy Loading and specifically load included tables

▼魔方 西西 提交于 2019-12-04 05:48:51
问题 Our current system is using Lazyloading by default (it is something I am going to be disabling but it can't be done right now) For this basic query I want to return two tables, CustomerNote and Note. This is my query using (var newContext = new Entities(true)) { newContext.Configuration.LazyLoadingEnabled = false; var result = from customerNotes in newContext.CustomerNotes.Include(d=>d.Note) join note in newContext.Notes on customerNotes.NoteId equals note.Id where customerNotes.CustomerId ==

How do I add properties to a Web API Response that I do not store in my DB?

有些话、适合烂在心里 提交于 2019-12-04 05:25:32
问题 I am building a C# Web API using Entity Framework 6.0. I have the simplest User Class with 3 properties that I persist on SQL into a User Table with 3 corresponding columns where UserID is its the Primary Key. public partial class User { public string UserID {get; set;} public string FirstName {get; set;} public string LastName {get; set;} } I want to add to the Web API two output-only properties on the fly that I do not care to store in my DB. I use these properties to communicate to the

How do I serialize an IdentityUser reference in Web API 2.2?

心已入冬 提交于 2019-12-04 05:09:28
问题 The Visual Studio "Web API" project template includes endpoints for handling registration, authentication, and authorization of users. In a production application, however, users will typically be associated with other Entities as well, such as: public class Post { public Post() {}; public int Id { get; set; } public ApplicationUser User { get; set; } } In these scenarios, the ApplicationUser class (which is derived from IdentityUser ) cannot be serialized. Attempting to do so will yield an

EntityFramework Stored Proc Function Import is it possible to read async?

不羁岁月 提交于 2019-12-04 04:57:29
I'm using EF 6.1.1 and Database First. When I import a stored proc into the edmx and generate the DBContext it looks like this: return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<TestSP_Result>("TestSP", params[]...) That returns an ObjectResult< T >, which implements IDbAsyncEnumerable< T > so I'm doing this to read the data async: IDbAsyncEnumerable<T> enumerable = objectResult as IDbAsyncEnumerable<T>; IDbAsyncEnumerator<T> enumerator = enumerable.GetAsyncEnumerator(); List<T> list = new List<T>(); bool moreItems = await enumerator.MoveNextAsync(CancellationToken.None);

How to re-create initial migration on the same .cs file

末鹿安然 提交于 2019-12-04 04:54:55
As common in EF Code First I've generated an "Initial Create" migration file where is located an outdated model of my db (I'm developing the app so the model is still changing). Now I have a "new model" defined in my code and instead of creating a new migration for that I just want to update the already existing file, because it still is the initial create migration. I've tried using this without any luck Update-database -targetmigration $initialcreate It returns Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either

EF6 - ExecuteSqlCommandAsync - Get return parameter (declare scalar variable error)

主宰稳场 提交于 2019-12-04 04:20:00
问题 I have the following code: object[] parameters = { new SqlParameter("@val1", val1), new SqlParameter("@val2", val2), new SqlParameter { ParameterName = "@retVal", SqlDbType = SqlDbType.Int, Direction = ParameterDirection.ReturnValue, Value = -1 } }; await context.Database.ExecuteSqlCommandAsync("EXEC @retVal = Example_SP @val1, @val2", parameters); The SP I'm using is fine and returns a value in SQL MS fine. But when I execute it using EF I am told I 'must declare the scalar variable @retVal'

Combine Code First & Database First In Single Model?

对着背影说爱祢 提交于 2019-12-04 04:16:14
Is there a way to combine code-first and database-first in the same context? We are running into massive development-time performance problems when editing the EDMX file (it takes 1.5 minutes to save). I've moved our non-insert/update/delete UDFs/stored procs to some custom T4 templates that automatically generate model-first code, but I can't seem to get OnModelCreating to be called when EDMX is involved. Other things we've considered, but won't work for one reason or another: We can't (reasonably) separate our code to multiple contexts as there is a lot of overlap in our entity relationships