entity-framework

Associate tables from different databases - Entity Framework

不羁岁月 提交于 2020-02-19 20:22:40
问题 I'd like to know how to (if possible) associate tables from different databases using entity framework. I have one edmx for my "xyz" database and another for my "abc" I need to associate them using EF. I know how to fix this using FKs, but that's not what I want, I'd like to be able to do that using the visual editor, not adding, by hand, a FK to my DB. Here's a pratical example of what I'd like to accomplish: Table User - database: abc Table Message - database: xyz I'd like to associate User

The query is executing very slowly, is there any way to improve it any further?

一个人想着一个人 提交于 2020-02-19 10:01:20
问题 I have the following query, and because of a lot of SUM function calls, my query is running too slow. I have a lot of records in my database and I would like to get a report from the current year and last year (Last 30 days, Last 90 days and last 365 days) for each one: SELECT b.id as [ID] ,d.[Title] as [Title] ,e.Class as [Class] ,Sum(CASE WHEN a.DateCol >= DATEADD(MONTH,-1,GETDATE()) THEN a.col1 ELSE 0 END) as [Current - Last 30 Days Col1] ,Sum(CASE WHEN a.DateCol >= DATEADD(MONTH,-1

How to set created date and Modified Date to enitites in DB first approach

纵然是瞬间 提交于 2020-02-18 09:38:22
问题 In every SQL table in our application we have "CreatedDate" and "ModifiedDate" column. We are using DB first approach. When i save the data, i want these two column automatically populated. One approach is to have Default Value as getdate() on the SQL Table Column itself. So thats going to solve the problem partially. Meaning it will set the CreatedDate & ModifiedDate when entity is new. However when i am editing/updating the entity i want only ModifiedDate to be updated. There are lot of

How to set created date and Modified Date to enitites in DB first approach

耗尽温柔 提交于 2020-02-18 09:31:14
问题 In every SQL table in our application we have "CreatedDate" and "ModifiedDate" column. We are using DB first approach. When i save the data, i want these two column automatically populated. One approach is to have Default Value as getdate() on the SQL Table Column itself. So thats going to solve the problem partially. Meaning it will set the CreatedDate & ModifiedDate when entity is new. However when i am editing/updating the entity i want only ModifiedDate to be updated. There are lot of

Changes in IDENTITY column after EF core 3

妖精的绣舞 提交于 2020-02-16 02:39:32
问题 Until EF core version used in .donet core 2.2, after the .Add command, EF fills the key column with a big negative number. After 3.0 upgrade this does not happens anymore. Here is the code: var appointment = new Appointment { Date = DateTime.Today, ProfessionalId = schedule.ProfessionalId }; await service.AddAsync(appointment); string message = null; if (service.AddLastPrescription(appointment.Id, schedule.PacienteId)) .... The problem is that now the "appointment.Id" is zero and the call to

Entity framework error: The conversion of a datetime2 data type to a datetime data

我的未来我决定 提交于 2020-02-15 18:31:03
问题 I know there are a ton of posts about this issue but none of them seem to solve my problem. Here's the scenario: I have a CreateDate DateTime column in my MS SQL Server database User table that is non-nullable and is automatically set using GetDate() method in "Default Value or Binding" setting. I am able to create a User just fine with the standard EF Insert but when I try to update the user, I get this error: The conversion of a datetime2 data type to a datetime data type resulted in an out

Cannot implicitly convert type 'void' to 'int'?

天涯浪子 提交于 2020-02-15 05:55:04
问题 Oke so I am fairly new to programming and I don't get why I get this error. My method should store mails which it does in this method: public void StoreMail(PhishingMail PhishingMail) { using (var phishingMailStorage = new PhishFinderModel()) { phishingMailStorage.PhishingMail.Attach(PhishingMail); phishingMailStorage.SaveChanges(); } And then in my processPhishingMail method it calls the Store method. But then I get the error: Cannot implicitly convert type 'void' to 'int'. public void

Cannot implicitly convert type 'void' to 'int'?

怎甘沉沦 提交于 2020-02-15 05:54:07
问题 Oke so I am fairly new to programming and I don't get why I get this error. My method should store mails which it does in this method: public void StoreMail(PhishingMail PhishingMail) { using (var phishingMailStorage = new PhishFinderModel()) { phishingMailStorage.PhishingMail.Attach(PhishingMail); phishingMailStorage.SaveChanges(); } And then in my processPhishingMail method it calls the Store method. But then I get the error: Cannot implicitly convert type 'void' to 'int'. public void

Code-first migration: How to set default value for new property?

我是研究僧i 提交于 2020-02-12 17:35:21
问题 I am using EF6 for storing instances of the report class in my database. The database already contains data. Say I wanted to add a property to report , public class report { // ... some previous properties // ... new property: public string newProperty{ get; set; } } Now if I go to the package-manager console and execute add-migration Report-added-newProperty update-database I will get a file in the '/Migrations' folder adding a newProperty column to the table. This works fine. However, on

Code-first migration: How to set default value for new property?

与世无争的帅哥 提交于 2020-02-12 17:33:33
问题 I am using EF6 for storing instances of the report class in my database. The database already contains data. Say I wanted to add a property to report , public class report { // ... some previous properties // ... new property: public string newProperty{ get; set; } } Now if I go to the package-manager console and execute add-migration Report-added-newProperty update-database I will get a file in the '/Migrations' folder adding a newProperty column to the table. This works fine. However, on