ef-code-first

Can I use Data Annotations or Fluent to convert a value between data store and entity class?

心不动则不痛 提交于 2020-01-05 07:28:40
问题 I am working with an existing [poorly designed] database which stores a dollar amount as an integer (ie. $10.99 == 1099) in the database. I want my entity class to treat this value as a decimal so that consuming code doesn't have to do the translation. Is there a way to convert the value to and from integer to decimal and then back using Data Annotations or Fluent configuration? In the meantime I am using a hack which essentially "wraps" the integer property with a decimal property that

EF Core - How can I retrieve associated entities of an aggregate root?

吃可爱长大的小学妹 提交于 2020-01-05 04:27:12
问题 In my app I am trying to follow DDD whilst modelling a simple fund account. The classes are FundAccount public Guid Id { get; set; } private ICollection<AccountTransaction> _transactions = new List<AccountTransaction>(); public IReadOnlyCollection<AccountTransaction> Transactions => _transactions .OrderByDescending(transaction => transaction.TransactionDateTime).ToList(); AccountTransaction public Guid Id { get; set; } public decimal Amount { get; set; ) I am trying to retrieve the fund

How to generate code first migration script from a specific migration?

六月ゝ 毕业季﹏ 提交于 2020-01-05 03:36:12
问题 I have a production and a development database. Now I want to generate a sql script based on a specific migration. When I enter the line to generate the script I get this error: '201608121243147_AutomaticMigration' is not a valid migration. Explicit migrations must be used for both source and target when scripting the upgrade between them. The command I use is as follows: Update-Database -Script -SourceMigration:201608121243147_AutomaticMigration -TargetMigration:201608281101542

Issue creating DbContext connection with LINQPad using Entity Framework 6.0 code first

时间秒杀一切 提交于 2020-01-04 15:29:19
问题 I'm using LINQPad v4.51.03 and attempting to create a DbContext connection from a code-first implementation in Entity Framework 6.0 (6.1.1). public partial class MyEntities : DbContext { public MyEntities() : base("mydbname") { ... The connection string looks like: <add name="mydbname" connectionString="Data Source=<db>;initial catalog=<cat>;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.EntityClient" /> In the LINQPad 'Add

Entity Framework Code-First too slow at startup

我只是一个虾纸丫 提交于 2020-01-04 10:14:12
问题 I know this has been asked a lot before, but I still haven't found a working fix. I'm creating a desktop application which will regularly be started and stopped. The database is a MySQL database stored online and I'm using the newest version of EF and the MySQL connector. I'm also working code-first. For now, I only have 3 small entities, but these will grow a lot in time. The database is generated already at startup, so nothing needs to be created anymore. Every time the application is

Entity Framework Code-First too slow at startup

流过昼夜 提交于 2020-01-04 10:11:13
问题 I know this has been asked a lot before, but I still haven't found a working fix. I'm creating a desktop application which will regularly be started and stopped. The database is a MySQL database stored online and I'm using the newest version of EF and the MySQL connector. I'm also working code-first. For now, I only have 3 small entities, but these will grow a lot in time. The database is generated already at startup, so nothing needs to be created anymore. Every time the application is

“Column names in each table must be unique.” during database update

╄→尐↘猪︶ㄣ 提交于 2020-01-04 09:39:21
问题 I am quite new to ASP.NET at all, however this is my first app with ASP.NET Core. I have problem with updating database after creating the migration. While I type command: dotnet ef database update , I get error: Column names in each table must be unique. Column name 'PortalUserId' in table 'Adverts' is specified more than once. I think the problem is with my model structure, but I do not know what I am doing wrong. When I was developing with ASP.NET MVC 5 everything was Ok. Here is my Model

Configuring many One-To-One relationships with Entity Framework Code First and Fluent API

送分小仙女□ 提交于 2020-01-04 05:28:08
问题 I have a horrible database model (in MySQL though I don't think that matters) that someone else designed so I'm stuck with it, but want to use with Entity Framework with it anyway: Database Item ASSET_ID* ASSET_NAME FIELDS_ID 1 Cat 1 2 Dog 2 3 Fish 3 ItemFields ID* CUSTOMFIELD1ID CUSTOMFIELD2ID CUSTOMFIELD3ID 1 1001 1002 1003 2 1004 1005 1006 3 1007 1008 1009 Field ID* STRINGVAL 1001 Meow Mix 1002 House 1003 5lbs 1004 Kibble 1005 Yard 1006 30lbs 1007 Fish Food 1008 Tank 1009 0.5 ounces

EF Code First - Linq to Entities Union EqualityComparer

♀尐吖头ヾ 提交于 2020-01-04 04:14:30
问题 I have two IEnumerable collections that I would like to union. One selects news objects that are associated with a particular category. When a user is filtering by a category I would also like news articles that have been tagged with another category to be displayed. So I have another query that returns news objects that are tagged with the particular sub category. Now I would like to union the two collections, removing duplicates (as a news article associated to the main category, may also

Code First Multiple Foreign Keys for One to Many Relation

丶灬走出姿态 提交于 2020-01-04 02:49:06
问题 I'm running into some problems departing from convention using Entity Framework 6, Code First Fluent API. A classic example is that I have an entity called Software. I don't want the db table to be called Softwares. It should be called Software. But there are a few other departures as well. The problem is, 2 columns are being created for a foreign key where only 1 should be. For example, in my domain, the is a 1:m relationship between SoftwareFiles and Software. (The logic being that there