entity-framework-6

Can we use enums as typesafe entity ids?

僤鯓⒐⒋嵵緔 提交于 2020-01-31 03:11:13
问题 We are working with a rather large model in a EF 6.1 code first setup and we are using ints for entity ids. Unfortunately, this is not as typesafe as we would like, since one can easily mix up ids, for example comparing ids of entities of different types (myblog.Id == somePost.Id) or similar. Or even worse: myBlog.Id++. Therefore, I came up with the idea of using typed ids, so you cannot mix up ids. So we need a BlogId type for our blog entity. Now, the obvious choice would be to use an int

Can we use enums as typesafe entity ids?

家住魔仙堡 提交于 2020-01-31 03:10:30
问题 We are working with a rather large model in a EF 6.1 code first setup and we are using ints for entity ids. Unfortunately, this is not as typesafe as we would like, since one can easily mix up ids, for example comparing ids of entities of different types (myblog.Id == somePost.Id) or similar. Or even worse: myBlog.Id++. Therefore, I came up with the idea of using typed ids, so you cannot mix up ids. So we need a BlogId type for our blog entity. Now, the obvious choice would be to use an int

Adding new entries over entity navigation property collection

喜欢而已 提交于 2020-01-30 12:16:06
问题 I need to create a generic way to add missing languages entries to all entities in which implements an specific interface. I found out how to get my collection property, but I still don't know how to add new values on it before proceed to save. Following a piece of my public override int SaveChanges() handling. foreach (var translationEntity in ChangeTracker.Entries(<ITranslation>)) { if (translationEntity.State == EntityState.Added) { var translationEntries = translationEntity.Entity.GetType

Unable to update database to match the current model

天涯浪子 提交于 2020-01-25 20:38:07
问题 I created a fresh Azure Mobile Services project and published to a newly created service on Azure. I then published the project to Azure and verified that I could post/get from it. Next, I enabled migration via the nuget manager console by following a guide i found online online and that I found on MSDN to set up data migration. I walked through the steps, adding my initial migration and re-publishing it to Azure. I did not make any changes to my models. The only thing I did after the first

How are people unit testing with Entity Framework 6, should you bother?

喜你入骨 提交于 2020-01-24 21:05:08
问题 I am just starting out with Unit testings and TDD in general. I have dabbled before but now I am determined to add it to my workflow and write better software. I asked a question yesterday that kind of included this, but it seems to be a question on its own. I have sat down to start implementing a service class that I will use to abstract away the business logic from the controllers and map to specific models and data interactions using EF6. The issue is I have roadblocked myself already

EF One-to-One Update fails

て烟熏妆下的殇ゞ 提交于 2020-01-24 16:15:49
问题 I have one-to-one relationship defined in EF6 which works for Inserts. Unfortunately when I try an update with a disconnected record, I receive an error. Here are details: .NET Source: namespace EF_ConsoleApp_Test { public class Program { public static void Main(string[] args) { int? accountId; int? customerId; using (var db = new MainContext()) { var account = new Account { AccountNumber = "1234", Customer = new Customer {FirstName = "John"} }; db.Accounts.Add(account); db.SaveChanges();

EF One-to-One Update fails

给你一囗甜甜゛ 提交于 2020-01-24 16:15:14
问题 I have one-to-one relationship defined in EF6 which works for Inserts. Unfortunately when I try an update with a disconnected record, I receive an error. Here are details: .NET Source: namespace EF_ConsoleApp_Test { public class Program { public static void Main(string[] args) { int? accountId; int? customerId; using (var db = new MainContext()) { var account = new Account { AccountNumber = "1234", Customer = new Customer {FirstName = "John"} }; db.Accounts.Add(account); db.SaveChanges();

Updating Nested Objects in Entity Framework

余生颓废 提交于 2020-01-24 04:12:48
问题 recently I discover that EF doesn't update nested object. For few days I try to figure out how to do this but unfortunately I'm stuck with this problem. I have Object public class ProjectEntity : AuditableEntity<int> { public string CustumerCompany { get; set; } public string CustomerRepresentative { get; set; } public string ProjectTitle { get; set; } public string WwsNumber { get; set; } [ForeignKey("ParentProjectId")] public virtual ProjectEntity ParentProject { get; set; } public int?

Add EF 6.x EntityObject Generator in Visual Studio 2017

…衆ロ難τιáo~ 提交于 2020-01-23 12:25:08
问题 We are planning to switch to Visual Studio 2017. For our Entity Framework 6 edmx file we use the EntityObject Generator extension to create us the desired ObjectContext. This extension is only compatible up to VS2013 - inofficially up to VS2015. The solution to simply adjust the manifest file in the vsix does not seem to work for VS2017 though - I guess among others because the vsix architecture changed. Is there a way to get the ObjectContext template without using an old Visual Studio? I

Migrations is enabled for context ''but the database does not exist or contains no mapped tables

倖福魔咒の 提交于 2020-01-23 09:50:12
问题 CreditoImobiliarioBB.Web All interface are defined here. Has reference to the project CreditoImobiliarioBB.EntityFramework and EF6. No configuration (we use FluentApi) or migrations is defined here. CreditoImobiliarioBB.EntityFramework Here is defined our generic repository and DbContext. All configurations and migrations are implemented here . CreditoImobiliarioBB.Domain Our design domain. Here are all our domain classes and interfaces (eg IEntity ) CreditoImobiliarioBB.Repository Here is