How can I modify edmx and reflect changes in the domainservice automatically? - silverlight

I have a silverlight business application created with vs2010 and it is RIA service enabled, I added new table in the database and updated the edmx using (update model from database option), but I want to update the domain service class as well to include the new tables, how can I do that?

I haven't found a way to do this automatically, but this blog seems helpful.
EDIT: If you use partial classes as suggested, then you can delete the DomainService1.cs class and use add new item to add the class again. Then using the built in wizard, re-check the entities you want to expose. The partial classes will hold your custom logic.

Unfortunately I have not found nothing better than:
Add new DomainService that will work with new table;
Copy generated code into existing(main) service (Get*, Insert, Update, Delete etc.);
Copy metadata;
Delete "new" DomainService and "new" metadata files;
After these steps you'll get access to your table.
NOTE:
*-without Get- method client will not recognize any changes;

Related

Context Lifetime on a WinForms app .Net6 with Dependency Injection

I am having some issues with context lifetime on my .NetCore 6 win forms application. In summary, I have a button that when clicked calls a repository which then retrieves a record from my DB and displays one value from that record in a text field. This works ok until that value changes in the database. Further clicks of the button continue to display the old value.
This is how I register my context in the winforms app
services.AddDbContext<MyContext>(b => b.UseSqlServer(connectionString));
I then register my services like this:
services.AddScoped<IMyRepo, MyRepo>();
I guess this is an issue where the form is long running and never disposes the context, hence why the result is always the same until the form is closed and reopened with a fresh context.
I am using this in my repo to force a new result each time, however is seems like a bit of a mission to do this for every request to the DB I make...
_entities.Entry(log).Reload();
Is there a cleaner way I can do this without having to do the reload?
Honestly, I wouldn't use the MS IoC AddDbContext for WinForms/WPF. There probably is a way to have it play nice with some form of lifetime scope, but I'm honestly not aware of one. I don't use it for web projects either, simply because it scopes the DbContext to the request and I like to have a bit more control over the lifetime of the DbContext in some situations. (Dealing with poisoned contexts for instance)
For web and WPF I've used a Unit of Work pattern called the DbContextScope to manage the DbContext and relationship with the Repositories. The idea being that the consumers use an injected DBContextScopeFactory to create a DbContextScope (wrapping one or more DbContext instances) and the Repositories accept an injected DbContexScopeLocator to gain access to a requested DbContextScope.
The original EF6 implementation was by Medhi El Gueddari (https://github.com/mehdime/DbContextScope || https://www.nuget.org/packages/Mehdime.Entity)
For EF Core 6: (https://www.nuget.org/packages/Zejji.DbContextScope.EFCore6)
Alternatively if the scope of a DbContext can be contained within the repository calls themselves (tracked entities don't need to be passed outside of the repository) then you could also just use an injected DbContextFactory class to provide DbContext instances on demand. The advantage of a UoW pattern like above is that you have control over the scope the DbContext instance(s) live so multiple operations can be committed together or rolled back. The DbContext instance is available between multiple repositories if needed.

Oracle ADF - CommandImageLink is not working

We are developing a web application using Oracle ADF. We have a view object based on query. we drag and dropped this view object as a table in a jsf page(suppose page1). For that table we have added a new column contains a commandImageLink.
From another page we are adding some data to DB using ADF DC, that should be reflected in page1. Actually its not working after that we googled and got solution that if I set CacheResults to false of that table Iterator in Binding layour it will work. I have set to false and reflection is happening.
But my problem is if I set CacheResults to false my commandImageLink is not working. If I set CacheResults to true my commandImageLink is working(navigation is happening).
Please help.
First of all:
I would presume that your page1 is part of a bounded task flow. If you are not, you should refactor your code and move the page in a bounded task flow. I would further presume you are using ADF Business Components for your model layer.
Second of all:
Never use CacheResults=false. That solution is a nonsense from ADF perspective.
Now, your problem is re-querying the table info on page opening, therefore:
Expose View Object Implementation for your VO. Override executeQuery() method in the newly created java class. Expose this method as client method (this should make the method PUBLIC, visible from Data Controls).
drag and drop executeQuery method into your task flow, as method action. Make sure you have this method action as the start activity of your task flow. Furthermore, make sure you are connecting executeQuery() to your page activity in the task flow. This will make sure that every time you open the page, execute query is fired.

Entity Namespace does not appear in Silverlight project

I have a Silverlight web project where I apply the MVVM pattern. In my entire solution I have 4 projects.
Project "A3", which contains all of my Views and ViewModels.
Project "A3.Web", which contains my main html files, images, sound files, etc.
Project "A3Lib", which contains my XAML binding converters and other helpful classes that I created.
Project "A3Lib.Web", which contains the Data Models and Domain Logic.
All of my entity models are inside my DataModels folder and all of my Domain Service server side code is inside the DomainLogic folder. I created a new folder inside the DataModels folder named "Common".
So when I want to add the data model to my VM, I tried "using A3Lib.Web.DataModels.Common;" and that did not find the namespace.
Issue: when I add a new folder and a new entity model to the DataModels folder, I do not see the namespace in my View or ViewModel in the "A3" project.
However, I already have existing code there (was added by someone else) and the models he added show perfectly fine (when doing using ...... in the View or VM).
I checked web.config to make sure the connection string is there and it's correct. I also tried to add a brand new context to the base class of the project (where other contexts are) and that did not help. My project simply cannot resolve or see the data model namespace that I create.
Thanks
Yura
The Silverlight app sees the models and namespaces from the server-side project through the generated code - you should see it in the Generated_Code folder of your A3Lib project. If it is not there, then the proxy classes are not being generated on build. A couple things to check:
class is not private (hey - sometimes it's the simple things)
if using Domain Services, the service needs to have at least 1 method that returns an IQueryable or IEnumerable (even if method returns null) in order to see the class in the Silverlight-side domaincontext
if the class is just a utility class that you want to share with the client, save the file as classname.shared.cs, and the proxy will pick it up.
make sure the project references are to the projects and not (possibly older) .dlls in another location.
That's all I've got based on the info provided.

MVC design for archived data view

Implementation of a standard archive process in ASP.Net MVC. Backend SQL Server 2005
We've an existing web app built in MVC. We've an Entity "Claim" and it has some child entities like ClaimDetails, Files, etc... A pretty standard setup in DB. Each entity has its own table and are linked via FK. Now, we need to have an "Archive" feature in web app which will allow admin to archive a Claim and its child entities. An archived Claim shud become readonly when visited again.
Here're some points on which I need your valued opinion -
To keep it simple and scalable (for a few million records) for now we plan to simply add a bit field "Archived" to the Claim table in db.
And change the behavior accordingly in the web app.
We've a 'Manage claim' page which renders a bunch of diff views for Claim and its child entities. Now, for a readonly view we can either
use the same views or have a separate set of views. What do you
suggest?
At controller level, we can identify archived claim and select which view to render.
At model level, though it'd be great to be able to use the same model used for Manage Claim - but it might not get us the "text" of
some lookup fields. For example, Claim.BrandId is rendered as a
dropdown in Manage claim (requires only BrandId) but for readonly view
we need 'BrandText'.
Any existing ref or architecture level example would be great.
Here's my prev SO post but its more about db level changes: Design a process to archive data (SQL Server 2005)
Thank you.
I ended up using a duplicate of the existing view with some edits and archive specific changes. I was able to use the same backend model and data fetch structure in a different action.
My entity table has an archived flag which helps identify the status so the rest of the fetch implementation stays the same only a new view (mostly replicated) and a new action (replicated from the existing one) got me the archived view.

Data conflict resolution in Silverlight with WCF Service

When using Silverlight together with a WCF Services library how do you solve the age old possibility of two different users loading a record, making different changes to that record and then updating. In other words when updating how does the WCF service know that the data it retrieved is the same as the data it fetched before applying an update?
Do you need to check the original loaded values against the values in the database (i.e. recall the original query before updating)?
I was hoping that there would be a more out-of-the-box answer.
Do you mean using EntityFramework? If so, here is the strategy I used :
When retrieving data on the client side you see that the "RowState" property of the entity is gone. What I did is I added the property on the client side using the "partial class" feature. And I manage locally the value of that RowState value.
When the data goes back to the server for update only send what has been modified filtering by the "RowState" property.
On your Update method, call the ApplyCurrentValues() method of the object.
Maybe there is a better solution for that, but that's what I am using on my project; and it works well on my case :)
Good luck

Resources