entity-framework

Linq-To-Entities using method to select new object

早过忘川 提交于 2020-12-09 08:05:50
问题 I try to use the same select query multiple times in my application. For example I have this select statement: _db.tbl_itembundlecontents .Select(z => new SingleItemDTO { amount = z.amount, id = z.id, position = z.position, contentType = new BasicMaterialDTO { id = z.tbl_items.id, img = z.tbl_items.tbl_material.img, name = z.tbl_items.tbl_material.name, namekey = z.tbl_items.tbl_material.namekey, info = z.tbl_items.tbl_material.info, weight = z.tbl_items.tbl_material.weight } }); but i also

Linq-To-Entities using method to select new object

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-09 08:03:32
问题 I try to use the same select query multiple times in my application. For example I have this select statement: _db.tbl_itembundlecontents .Select(z => new SingleItemDTO { amount = z.amount, id = z.id, position = z.position, contentType = new BasicMaterialDTO { id = z.tbl_items.id, img = z.tbl_items.tbl_material.img, name = z.tbl_items.tbl_material.name, namekey = z.tbl_items.tbl_material.namekey, info = z.tbl_items.tbl_material.info, weight = z.tbl_items.tbl_material.weight } }); but i also

Entity Framework Core 2.2 : Disable migrations for specific entities

拥有回忆 提交于 2020-12-08 13:41:29
问题 I'm trying to build an aspnetcore application over an existing system where the database is already created, and I'm going to add some tables over it. I've reverse engineered the database to add the existing tables as entities to my application, and I've written my own entities that will be added later. Finally, all the entities are added to a single DbContext. My requirement comes as follows: I want to enable code first migrations for the newly added entities I don't want the migrations to

Entity Framework Core 2.2 : Disable migrations for specific entities

╄→尐↘猪︶ㄣ 提交于 2020-12-08 13:32:28
问题 I'm trying to build an aspnetcore application over an existing system where the database is already created, and I'm going to add some tables over it. I've reverse engineered the database to add the existing tables as entities to my application, and I've written my own entities that will be added later. Finally, all the entities are added to a single DbContext. My requirement comes as follows: I want to enable code first migrations for the newly added entities I don't want the migrations to

Entity Framework Core 2.2 : Disable migrations for specific entities

99封情书 提交于 2020-12-08 13:30:49
问题 I'm trying to build an aspnetcore application over an existing system where the database is already created, and I'm going to add some tables over it. I've reverse engineered the database to add the existing tables as entities to my application, and I've written my own entities that will be added later. Finally, all the entities are added to a single DbContext. My requirement comes as follows: I want to enable code first migrations for the newly added entities I don't want the migrations to

How to stop EF Core from indexing all foreign keys

谁说我不能喝 提交于 2020-12-08 06:58:22
问题 As documented in questions like Entity Framework Indexing ALL foreign key columns, EF Core seems to automatically generate an index for every foreign key. This is a sound default for me (let's not get into an opinion war here...), but there are cases where it is just a waste of space and slowing down inserts and updates. How do I prevent it on a case-by-case basis? I don't want to wholly turn it off, as it does more good than harm; I don't want to have to manually configure it for all those

How Many DBContext's Should I have

瘦欲@ 提交于 2020-12-08 05:26:09
问题 Using Entity I currently have dbcontext that has every table in it. I'm wondering if that's what everyone does, or do you have a context per module for example. To me the dbcontext was a connection to map the models to a database, and since there is only one database, I only need one. Before I get too far along I want to see if that's appropriate. So 1 db context per database or many? 回答1: I went through this same process recently and found some great resources on the subject. Here are a

Cannot insert the value NULL into column 'Id', Entity framework

我与影子孤独终老i 提交于 2020-12-06 07:49:52
问题 I have the following model: Services.StradaDataReview2Model.UOSChangeLog: [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int Accident_nr { get; set; } public int Refnr { get; set; } public int Action { get; set; } public string Old_data { get; set; } public string New_data { get; set; } public DateTime SearchedFromDate { get; set; } public DateTime SearchedToDate { get; set; } public DateTime Changed { get; set; } public string Username { get; set; }

Cannot insert the value NULL into column 'Id', Entity framework

*爱你&永不变心* 提交于 2020-12-06 07:49:37
问题 I have the following model: Services.StradaDataReview2Model.UOSChangeLog: [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public int Accident_nr { get; set; } public int Refnr { get; set; } public int Action { get; set; } public string Old_data { get; set; } public string New_data { get; set; } public DateTime SearchedFromDate { get; set; } public DateTime SearchedToDate { get; set; } public DateTime Changed { get; set; } public string Username { get; set; }

asp.net core 2.0 bind model with decimal value

时光总嘲笑我的痴心妄想 提交于 2020-12-05 11:14:35
问题 I've been looking for a solution to this case for hours, and I did not find anything that worked out for me. Here we use the comma for decimal separator, and when I send a value like "15,50", in my controller I get the value of the model as "1550", and it only makes sense if I send "15.50". I covered the following topics, and nothing worked. Set CultureInfo in Asp.net Core to have a . as CurrencyDecimalSeparator instead of , Aspnet Core Decimal binding not working on non English Culture I am