entity-framework

Using Razor to create a form for hierarchy of domain models

那年仲夏 提交于 2020-01-06 10:40:53
问题 Lets say I have the following classes (could you also consider if my classes in terms of that relation part is correct): public class EFDbContext : DbContext { public DbSet<Project> Projects { get; set; } public DbSet<Address> Addresses { get; set; } // * public DbSet<Country> Countries { get; set; } // * // Custom model builder bindings for * coz of the plural issue with EF } public class Project { public int ProjectID { get; set; } public string Name { get ; set; } public int AddressID {

Using Razor to create a form for hierarchy of domain models

…衆ロ難τιáo~ 提交于 2020-01-06 10:39:27
问题 Lets say I have the following classes (could you also consider if my classes in terms of that relation part is correct): public class EFDbContext : DbContext { public DbSet<Project> Projects { get; set; } public DbSet<Address> Addresses { get; set; } // * public DbSet<Country> Countries { get; set; } // * // Custom model builder bindings for * coz of the plural issue with EF } public class Project { public int ProjectID { get; set; } public string Name { get ; set; } public int AddressID {

Entity Framework Null Reference Exception

折月煮酒 提交于 2020-01-06 09:06:35
问题 I am trying to grasp EF Code First but I still do not get how to access the referenced objects from another class (due to lack of enough knowledge, I cannot even formulate the question). Here's what my simple code looks like: public class Destination { public int DestinationId { get; set; } public string Name { get; set; } public string Country { get; set; } public string Description { get; set; } public byte[] Photo { get; set; } public List<Lodging> Lodgings { get; set; } } public class

Entity Framework Null Reference Exception

旧街凉风 提交于 2020-01-06 09:05:16
问题 I am trying to grasp EF Code First but I still do not get how to access the referenced objects from another class (due to lack of enough knowledge, I cannot even formulate the question). Here's what my simple code looks like: public class Destination { public int DestinationId { get; set; } public string Name { get; set; } public string Country { get; set; } public string Description { get; set; } public byte[] Photo { get; set; } public List<Lodging> Lodgings { get; set; } } public class

How many repositories is too many?

℡╲_俬逩灬. 提交于 2020-01-06 08:43:17
问题 We are getting ready to modularize a large enterprise application that is currently using a dying stack of technologies. My question is in the Repository/Unit of Work pattern, how many Repositories can you have in a unit of work? Say for example we create a UnitOfWork on a single DbContext that exposes 50+ repository entities. Will this cause performance problems? We were looking at maybe splitting it up so that each schema has it's own DbContext but this seems to add a lot of complexity and

EF Code First table naming issues

做~自己de王妃 提交于 2020-01-06 08:38:09
问题 I have a project built using EF code first. It also uses forms authentication. Until recently the membership database and the application database were being developed separately, but I want to combine them into one database for simplicity. One of the classes in my code first model is called "Application" so the EF-generated table is called "Applications" which conflicts with a membership table of the same name. This is an example of my current context: public partial class ExampleContext :

optimisticconcurrencyexception was caught when updating entity relation using stub entities

穿精又带淫゛_ 提交于 2020-01-06 08:33:08
问题 This code is giving me optimisticconcurrencyexception was caught. I am simply using a Stub Entity to get an existing record and trying to update a couple values. I am not sure how to resolve the exception. Any help is very much appreciated: using (MiscEntities ctx = new MiscEntities()) { var m = ctx.Rates.FirstOrDefault(m => m.UserId == UserIdGuid); DataAccess.Rate oldDbRate = new DataAccess.Rate { RatingId = m.RatingId }; ctx.AttachTo("Rates", dbRate); dbRate.Rating = Rating; dbRate

How can I write custom comparison (definition for binary operator Equal) for entityframework object to an int?

蹲街弑〆低调 提交于 2020-01-06 08:32:26
问题 I'm getting this error: ex = {"The binary operator Equal is not defined for the types 'MySite.Domain.DomainModel.EntityFramework.NickName' and 'System.Int32'."} What I tried to do was do a select all where the NickNameId = someIntPassedIn ... the problem is that the NickNameId is a foreign key, so when it compares the someIntPassedIn to the NickNameId it pulls the whole NickName object that the NickNameId refers to and tries to compare the int to that object. I need a solution here to allow

Error Seeding Database? (MVC 4 Application, EF 5, Code-First)

孤人 提交于 2020-01-06 08:27:12
问题 I've successfully added a new migration in my project, but when I run update-database in Package Manager Console I receive: Error Seeding Privileges: An error occurred while updating the entries. See the inner exception for details. . Full Details: PM> update-database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No pending explicit migrations. Running Seed method. System.Exception: Error Seeding Privileges: An error occurred while updating the

EntityFramework One-To-Many fK?

馋奶兔 提交于 2020-01-06 08:23:06
问题 BasketItem duplicateBasketItem = (from ph in storeDB.BasketItems where ph.sellerSKU == newItem.sellerSKU select ph).SingleOrDefault(); {"Invalid column name 'BasketID'."} My Classes: public class Basket { [Key] public string BasketID { get; set; } public virtual IList<BasketItem> BasketItems { get; set; } public int? Count { get; set; } public System.DateTime DateCreated { get; set; } public Guid UserID { get; set; } } public class BasketItem { [Key] public int BasketItemID { get; set; }