entity-framework

Nullable DateTime conversion [duplicate]

那年仲夏 提交于 2020-04-29 07:15:40
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: c# why cant a nullable int be assigned null as a value Im trying to convert my reader[3] object which is datetime to be null if there is no lastPostDate for a Forum but it says Im missing a conversion. Error: Type of conditional expression cannot be determined because there is no implicit conversion between <null> and 'System.DateTime' public class Forums { public List<Forum> GetForums() { using (SqlConnection

Nullable DateTime conversion [duplicate]

陌路散爱 提交于 2020-04-29 07:15:19
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: c# why cant a nullable int be assigned null as a value Im trying to convert my reader[3] object which is datetime to be null if there is no lastPostDate for a Forum but it says Im missing a conversion. Error: Type of conditional expression cannot be determined because there is no implicit conversion between <null> and 'System.DateTime' public class Forums { public List<Forum> GetForums() { using (SqlConnection

Linq to EF - Unsupported Functions

只谈情不闲聊 提交于 2020-04-28 17:51:53
问题 I'm making a query with Linq, backed by an Entity Framework datasource. I'm getting the following error: LINQ to Entities does not recognize the method 'Double Sqrt(Double)' method, and this method cannot be translated into a store expression. Here's a simplified version of my function (my version is more complex and uses ACos, sin, cos and other C# Math class functions). var objects = from n in context.Products.Where(p => p.r == r) let a = Math.Sqrt((double)n.Latitude) where a < 5 orderby a

Linq to EF - Unsupported Functions

℡╲_俬逩灬. 提交于 2020-04-28 17:43:40
问题 I'm making a query with Linq, backed by an Entity Framework datasource. I'm getting the following error: LINQ to Entities does not recognize the method 'Double Sqrt(Double)' method, and this method cannot be translated into a store expression. Here's a simplified version of my function (my version is more complex and uses ACos, sin, cos and other C# Math class functions). var objects = from n in context.Products.Where(p => p.r == r) let a = Math.Sqrt((double)n.Latitude) where a < 5 orderby a

Cannot resolve DbContext in ASP.NET Core 2.0

帅比萌擦擦* 提交于 2020-04-26 13:33:56
问题 First of all, I'm trying to seed my database with sample data. I have read that this is the way to do it (in Startup.Configure ) (please, see ASP.NET Core RC2 Seed Database) I'm using ASP.NET Core 2.0 with the default options. As usual, I register my DbContext in ConfigureServices . But after that, in the Startup.Configure method, when I try to resolve it using GetRequiredService , it throws with this message: System.InvalidOperationException: 'Cannot resolve scoped service 'SGDTP

Cannot resolve DbContext in ASP.NET Core 2.0

*爱你&永不变心* 提交于 2020-04-26 13:33:46
问题 First of all, I'm trying to seed my database with sample data. I have read that this is the way to do it (in Startup.Configure ) (please, see ASP.NET Core RC2 Seed Database) I'm using ASP.NET Core 2.0 with the default options. As usual, I register my DbContext in ConfigureServices . But after that, in the Startup.Configure method, when I try to resolve it using GetRequiredService , it throws with this message: System.InvalidOperationException: 'Cannot resolve scoped service 'SGDTP

The type of one of the expressions in the join clause is incorrect in Entity Framework. Constant in left join

限于喜欢 提交于 2020-04-21 08:14:14
问题 I'm trying to do a left join in an EF query. I'm getting the following error: Error CS1941 The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin' and here is the C# code: var foo = from m in db.ClientMasters join a in db.Orders on new { m.Id, Status = "N" } equals new { a.ClientID, a.Status } into a_join from a in a_join.DefaultIfEmpty() select new { m.ClientID, a.ID }; 回答1: I'm an idiot. The column names have to match in the join.

ASP.NET Core 2.1 Unable to run migrations due to environment variable

梦想与她 提交于 2020-04-18 12:50:38
问题 This is the structure of my project : App.UI App.Data (ClassLibrary project) App.UI contains some environment variables that I would like App.Data to have access to such as the connection string. The problem now is that when I try to do a migration like this: Add-Migration AppOneBaseMigration -Context AppDbContext -OutputDir Migrations\AppOneMigrations I get this error: System.ArgumentNullException: Value cannot be null. Parameter name: path This is the code that initialises when I run my

ASP.NET Core 2.1 Unable to run migrations due to environment variable

送分小仙女□ 提交于 2020-04-18 12:49:09
问题 This is the structure of my project : App.UI App.Data (ClassLibrary project) App.UI contains some environment variables that I would like App.Data to have access to such as the connection string. The problem now is that when I try to do a migration like this: Add-Migration AppOneBaseMigration -Context AppDbContext -OutputDir Migrations\AppOneMigrations I get this error: System.ArgumentNullException: Value cannot be null. Parameter name: path This is the code that initialises when I run my

Cannot set bool value to false in entity framework update method

柔情痞子 提交于 2020-04-18 05:57:32
问题 I got strange problem when I try to update existing entity. public void Update(VisitDTO item) { using (var ctx = new ReceptionDbContext()) { var entityToUpdate = ctx.Visits.Attach(new Visit { Id = item.Id }); var updatedEntity = Mapper.Map<Visit>(item); ctx.Entry(entityToUpdate).CurrentValues.SetValues(updatedEntity); ctx.SaveChanges(); } This is my update method. In enity Visit I got some bools values, but i cannot set these to false , when it comes to update from false to true its okay but