can microsoft sync framework sync database views ?
or in your SelectIncrementalInsertsCommand can you select and join to multiple tables kinda doing something like a view?
Sync Framework does not support Views. You can changes the SelectIncrementalInsertsCommand to return data, however you need to make sure it gives back exact schema expected, no extra columns no mis matched data types. There is another way if your scenario really demands extra info. You can manipualate the data set retrieved in the ChangesSelected event of Provider. However you need to be careful about performance hit here.
Views are created dynamically on execution s you cant sync them.
BUT you can:
aggregate the view's data into a table and then sync the table.
Run the view on the synced tables on the target DB.
Related
I have a database which is created in a separate project and a .edmx model file is generated by Entity Framework and created the model classes from the existing database.
There are several things that are added to the database (other parts of the backend, front end site, api, etc). Currently the method I have is a loop that checks for new entries in the database every 5 seconds (basically just a call to the table that looks for entries newer than the most recent entry I know of), and then I use the entry to perform actions that are non database related.
I was wondering if there was a better way to get new entries as opposed to constantly querying the database for something new. I was wondering if what I'm doing is fine, or if there's a better way to get new entries, preferably able to be built upon/with EF.
Thanks for any help!
If you want to notify your app as soon as any database records are inserted or updated or deleted and do some extra processing on them then you have two choices.
You can go with SqlDependency or SqlTableDependency. Both are used to notify the application when something on database changes. There is just one constraint where you must be able to enable the Broker for SQL server using ALTER DATABASE MyDatabase SET ENABLE_BROKER (This is important as some db doesn't support broker services i.e SQL Azure )
Here are some good links to explore both the approaches.
https://github.com/christiandelbianco/monitor-table-change-with-sqltabledependency
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/detecting-changes-with-sqldependency
Background
I am starting a series of simple screens to display and update info in our ERP database.
I have worked through the wpf controls and understand the need for Observable Collections and after reading around on Entity Framework I understand the advantages of it sitting on top of ADO.net compared to the basic SQL methods and Datatables I am more comfortable with due to my SQL experience.
When I tried EF when I was first started working with Data CRUD screens I struggled to get the Observable Collections I needed, but having read this walk through last night ( https://msdn.microsoft.com/en-us/data/jj574514.aspx) and seen the notes for VS 2010 to edit EF code to get Observable Collections I think I want to try EF again.
Question
My Data screen needs present information which has be combined from five tables and a couple of sub views to be meaningful to the user.
Included in the dataview is a simple Y/N flag which comes from one of the five Datatables.
Can the user update the Y/N flag through the view mapped to EF, displayed in WPF datagrid ?
Or do I have to map all the base Datatables and sub views and recreate the view and Data Context in EF to allow the update to work?
If it is the latter does any one know of any tutorials or walk through I can use on my test development to try EF please
Thanks
The user can update a field via the view mapped to EF, however it is a little bit more complicated.
For a single table mapped to EF, the update is done by EF automatically, for a view mapped to EF you need to define the update function in the mapping details.
The function would be in form of an SQL stored procedure mapped to EF.
I have a table that used throughout an app by Entity. I have a view that returns an identical column set, but is actually a union on itself to try to work around some bad normalization (The app is large and partially out of my hands, this part is unavoidable).
Is it possible to have Entity 4 treat a view that is exactly like a table as the same type, so that I can use this view to populate a collection of the same type? This question seems to indicate it is possible in nhibernatem but I can't find anything like it for entity. It would be an extra bonus of the navigation properties could still be used to Include(), but this is not necessary (I can always manually join).
Since EF works on mappings from objects to database entities this is not directly possible. What you need is something like changing the queried database entity dynamically, and AFAIK this is not possible without manually changing the object context.
For sure the EF runtime won't care as long as it can treat the view as if it was completely separate table. The two possible challenges that I forsee are:
Tooling: Our wizard does allow you to select views when doing reverse engineering (i.e. database-first). Definitively if you can use 'code first against an existing database' you can just pretend that the view is just a table, but you won't get any help scripting the database creation or migrations.
Updates: in general you can perform updates for a view setting up store procedure mapping (which is available in the EF Designer from v1 or in Code First starting in EF6). You might also be able to make your view updatable directly or using instead off triggers (see "Updatable Views" here for more details). If I remember correctly the SQL generated by EF to retrieve database generated values (e.g. for identity columns) is not compatible in some cases with instead-off triggers. Yet another alternative is to have your application treat the view as read-only and perform all updates through the actual table, which you would map as a separate entity. Keep in in mind that in-memory entities for the view and the original table will not be kept in sync.
Hope this helps!
I am facing one problem. I am working on a project which has requirement of dynamically populating Grid control to add, update and remove records of specific table.
database is not finalized yet. so what i want is, if i add new column to a table and run the application. that grid should contain newly added column so that i can add new row. update or delete existing row.
I have crated DAL using LINQ to SQL but that is not covering my requirement. I want
Get name of tables from database and show them in dropdown list.
after selecting table name. grid should populate with all the columns. so that i can add/update/delete records.
So what exactly is your problem, you want to know how to get the table list from the database? If it is so, and if you're using SQL Server, you could run a select like that :
select name from sysobjects where xtype = 'U'
You can explore this system tables : sysobjects and syscolumns, they store the metadata information on the database.
From what I can gather, your best bet would be taking a different approach than Linq to SQL. You are looking for a UI which directly reflects your domain and can be generated automatically / dynamically. Two methods come to mind:
You can leverage MS Dynamic-Data which is an ASP.NET WebForms-based technology. You wire it up directly to a database or Entity Framework model. It generates the grids for all CRUD operations. It detects relationships via foreign keys and can generate the tables with links to one another. It's very customizable.
Dynamic Data
There is another architectural pattern called "Naked Objects". This requires rich, well-designed domain and aggregate roots. The UI should be 100% generated from this domain model. See the videos on this site to get a great example.
One example I can give you is, recently, our team has been divided - some working on an SOA application which integrates with our main product. Our developer resources are all focused on the task at hand writing WCF services, architecture, database engineering, ASP.NET, etc etc. We needed an internal application which we could use to administer the new SOA application. We could not dedicate another group of guys to build out a new application.
By using Dynamic Data, we had the entire administration app up and running off our EF 4 model in no time. It's doing everything we needed and minimal resources were exerted.
Use ADO.NET Entity Framework for your DAL than using LINQ TO SQL.
Well I solved this problem by getting table info from database schema.
build table to grid on run time which auto generates all columns.
created insert/update/delete query on fly by getting columns name from grid column name.
Happy coding:)
I have mobile application, so i dont want to send/receive whole changes in tables..Just some data, that meets some filter terms. Is it possible to achieve with SF; if it is, please provide some resources to read about it, because i found almost nothing.
Thank You.
Yes its possible. For example you might only want to sync the records relating to a specific store, rather than all the changes in the store table.
You do this by adding a parameter to the SyncParameters collection. e.g.
m_SyncAgent.Configuration.SyncParameters.Add("#ParamName", paramValue)
This will pass the parameter data to the serverside of the Sync process, which you can then use to sync only the data you want to include.
It's definitely possible with SQL Server Replication Services (SSRS). You can select which tables, fields, and even apply filters to the publication. I'm not familiar with Sync Framework but SSRS subscriptions appear in the Sync Center, so my assumption is that Sync Framework uses SSRS.