Forum Widgets
Latest Discussions
EF Core display up to date data on predefine delay
Hi, I have a C#/WPF project for which I use EF Core (database first) to transact with an SQL database. I am struggling with retreiving fresh data from the server on a predefine delay to be displayed on a dashboard. Scenario is this: I have an entity call Cars. Cars has a property that is a virtual ICollection of ToDo call lstToDo Each ToDo entity has a boolean property call Completed. The data of SQL database can be modified by many users. The dashboard is the application running on a computer that no one is using, and that need to display the latest data from the database every X minutes. So in my scenario everything is working fine except that whenever the property Completed is change, in the database, from false to true (or vice-versa) I am unable to get the new value. I tried using Eager Loading but without any luck.It will catch when a new row has been added to the table, but not when a change happen in an existing row. The eager loading I use: myContext.Cars .Include(c => c.lstToDo) .Load(); myCollectionViewSource.Source = myContext.Cars.Local.ToObservableCollection(); Also, in my context I configured it to use LazyLoading. Any suggestion will be more then welcomeAlex_is_programmingOct 03, 2024Copper Contributor97Views0likes0CommentsEntity framework core 8 return double quote in Oracle Query
Hi All, My project using .net core 8, when i debug code, always get error ".net core ORA-00942: table or view does not exist" i would like to show data using this query: var data = _db.employee.ToQueryString(); when i debug, the data variable show this: SELECT "e"."id", "e"."empolyee_name", "e"."employee_code" FROM "employee" "e" My Question: how to remove double quote " in EF query to this? SELECT e . id , e . empolyee_name, e . employee_code FROM employee e. i assume the error table or view does not existbecause my EF query returning double quote "". how to solve it? thanks & regards.tomtom2xOct 03, 2024Copper Contributor138Views0likes0CommentsCannot connect to LocalDB (provider: Named Pipes Provider, error: 0 - No process is at the other end
I'm trying to manually connect to LocalDB (both, SQL Server 2019 and SQL Server 2022 services) creating a new application database using ADO.NET (Microsoft.Data.SqlClient). Everytime I try to connect, I get a generic error telling me that the database file could not be attached. Error.log: 2024-09-17 19:30:18.40 Logon Error: 15350, Severity: 16, State: 1. 2024-09-17 19:30:18.40 Logon An attempt to attach an auto-named database for file C:\Temp\CvTest.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. 2024-09-17 19:31:02.66 Logon Error: 15350, Severity: 16, State: 1. 2024-09-17 19:31:02.66 Logon An attempt to attach an auto-named database for file C:\Temp\CvTest.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. Debugging into the Microsoft.Data.SqlClient source code, the following error turned out to be the real reason behind the issue: A connection to the server could be established, but an error occurred during the login process. (provider: Named Pipes Provider, error: 0 - No process is at the other end of the pipe). What is causing this error? This is my simple test connection setup. It's a cheap connection string that every Microsoft sample is quoting: using SqlConnection con = new SqlConnection(@"Data Source=(LocalDb)\MSSQLLocalDB;Integrated Security=SSPI;MultipleActiveResultSets=True;AttachDBFilename=C:\Temp\CvTest.mdf"); con.Open(); So, it should work off the cuff. But it doesn't. Using SSMS, I can easily connect to the LocalDB instance and create/delete databases promptly, even with the provided path. I already updated from MsLocalDb 15 to MsLocalDb 16, but to no avail.BetterTodaySep 24, 2024Brass Contributor120Views0likes0CommentsC# & EF Core : 2 databases with a Customertable and different Columns
Hello, I have a little PRoblem with my DbContext. For Example: I have two Databases both have a Table Customer. One of the Customers has an Extension of our Software so in the Customertable there are for example 3 more columns. Now when i create the DataAccess Class of the Customer Table i add the Structure from the Customer Table and the 3 extra columns. Now when i Request a Customer for the Customer with the extra Columns all is fine. The Request for the other Customer gets an Error that the last 3 Columns from the Model are not in the Table. Unfortunately it is not possible to add the Columns to the other Customer Table. so my Question is: Is there another Way to geht Records from both Databases with one Model Class and one DBContext? I tried NotMapped and Required in DbContext, I tried Raw SQL but nothing worked. The only Solution is to create 2 DbContexts. But in Our Database there are more such Combinations of Table with different Columns. Can anyone help or provide a way to test? Best Regards PhilipppwendelAug 01, 2024Copper Contributor140Views0likes0Comments.NET solution generator
We have released a free version of our product //entity.services that allows you to generate .NET solutions (including the fully customizable source code) based on simple definitions of your data models. You can find a quick start guide on the GitHub pagehttps://github.com/axlln/es-quick-start Please try it and let us know what you think Thanks, GorangoranJul 01, 2024Copper Contributor215Views0likes0CommentsEF Core : foreign key column with same name as existing navigation property
Iwant to use EF Core to map a legacy database. I cannot scaffold as there are hundreds of tables and I am only interested in very few and besides scaffolding generates names for the navigation properties which are not the ones I want. The situation is: I have a required many-to-one relationship linked by a column name that matches the name of the property that I want to give. The code (simplified) is: public class EntityProperty { public ControlType ControlType { get; set; } } public class ControlType { public List<EntityProperty> Properties { get; set; } = new List<EntityProperty>(); } Nothing more is required, eg, I'm not using foreign key properties, just navigation. The problem is, the foreign key column from theEntityPropertiestable to theControlTypesis also calledControlType. So, when I try to map it as: builder.HasOne(x => x.ControlType) .WithMany(x => x.Properties) .IsRequired() .HasForeignKey("ControlType"); I want to use EF Core to map a legacy database. I cannot scaffold as there are hundreds of tables and I am only interested in very few. The situation is: I have a required many-to-one relationship linked by a column name that matches the name of the property that I want to give. The code (simplified) is: public class EntityProperty { public ControlType ControlType { get; set; } } public class ControlType { public List<EntityProperty> Properties { get; set; } = new List<EntityProperty>(); } The problem is, the foreign key column from theEntityPropertiestable to theControlTypesis also calledControlType. So, when I try to map it as: builder.HasOne(x => x.ControlType) .WithMany(x => x.Properties) .IsRequired() .HasForeignKey("ControlType"); I get the following exception: InvalidOperationException: The property or navigation 'ControlType' cannot be added to the 'EntityProperty' type because a property or navigation with the same name already exists on the 'EntityProperty' type.' The problem is with HasForeignKey, I guess it's because I am adding a shadow property when a "physical" property already exists, but I what I really mean to say is to use a different column name to link the two entities: what I want is to be able to specify a "not standard" column name for the foreign key, which I am not able to. I do not have a foreign key property, only a navigation property, and I do not want to have one.SolvedRicardo PeresMay 20, 2024Copper Contributor1.6KViews0likes1CommentCan I ignore a single return value when multiple values are returned?
Some time ago, the ability to create a function which has multiple return values was created. Yes, I know this can be avoided by using out... but I was curious. In traditional method calls, the return value can be ignored by not assigning the return value to a variable. I recently decided to use multiple return values in a new method because I wanted to avoid having to worry about the method call when the return value isn't always used. Turns out that may have been an oversight on my part, since I as far as I know, I still have to define a return value. For example, if the return signature of "MyFunction" is (int, bool) and I don't need the bool value, I still have to define it (FAIK... which is the point here): private (int, bool) MyFunction(...) { bool error = false; int someReturnValue = 0; //... does something and sets error if there is a problem return (someReturnValue, error); } public void MyUnconcernedCallerFunction() { int ret; bool error; // what if I don't need to worry about the error here? (ret, error) = MyFunction(...); } is there currently any convention that allows me to not declare the bool error value if I don't need it? (i.e. can I ignore the bool part of the return?) SIDE NOTE: Why isn't there a general forum here? While my example is language specific, the question isn't. This is just a general .NET question having to do with data and there are no general options in the "Choose a Label" options. I couldn't post without choosing one so I just picked the one that made the most sense.primem0verMay 04, 2024Copper Contributor249Views0likes0Comments"Thread was interrupted from a waiting state" from DbConnectionPool.CleanupCallback
Hi, I'm getting this error, and I'm not able to fix it, or even understand from where it comes. I'm also sure that all my SqlConnection are instanciated with Using (VB.NET), so the Dispose should be called for every one. Does anyone have an idea about the cause? This error started after upgraded the app to the .NET Framework 4.8.1, from 4.6.2. Maybe it's a coincidence... Source: mscorlib; Message:Thread was interrupted from a waiting state.; Data:; StackTrace: at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext) at System.Data.ProviderBase.DbConnectionPool.CleanupCallback(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.TimerQueueTimer.CallCallback() at System.Threading.TimerQueueTimer.Fire() at System.Threading.TimerQueue.FireNextTimers(); Regards, PedroPedro-GoncalvesSep 07, 2023Copper Contributor2.9KViews0likes2CommentsSubject: Help & Support Case for ADO.NET Entity Framework back end changes & front end changes with
sync to Model & Database respectively. Help & Support Case From, Abhay Sakunde, Cognizant India Pvt. Ltd. Pune Project Team: MWS CWS Apps Team E-mail ID: (email removed for privacy reasons) Mobile No.: (phone number removed for privacy reasons) To, The Manager, Human Resources Or Development Team, Microsoft India Pvt. Ltd. Pune Subject: Help & Support Case for ADO.NET Entity Framework back end changes & front end changes with sync to Model & Database respectively. Hi Team, Initially using Entity Workflows: Program / Model / Database Priority, we do the design of ADO.NET Entity Data Model & development of database. But once initial process is done if any changes occur either as back end changes into database or front end changes into model then how we can manage or do synchronization between ADO.NET Entity Data Model & Database? How it is done with respect to different type of Entity Workflows i.e. Program / Model / Database Priority? There are following options like Update Model From Database Generate Database From Model In case of Entity Workflows - Model Priority, Initially Model is designed & database is generated. Now if model is changed only then option Generate Database From Model will work either to update existing database or new Database will get created? Please Clarify. In case of Entity Workflows - Database Priority, Initially database exists & model design is generated. Now, if model is changed only then option Generate Database From Model will work either to update existing database or new Database will get created? Please Clarify. Waiting for reply. Please let me know if any detail information required for mentioned feature. Screens: [1] Model & Database Options Thanks & Regards, Abhay SakundeABHAY_SAKUNDEMay 08, 2023Copper Contributor575Views0likes1Comment
Resources
Tags
- Entity Framework Core7 Topics
- ADO.NET7 Topics
- SqlClient6 Topics
- entity framework5 Topics
- ASP.NET Core1 Topic
- SQLite1 Topic