In the book of adrian hall, there is a sample which fetches objects with sub objects.
In this case it looks like this:
public class JobDTO : EntityData
{
public string AgentId { get; set; }
public DateTimeOffset? StartTime { get; set; }
public DateTimeOffset? EndTime { get; set; }
public string Status { get; set; }
public string Description { get; set; }
public virtual CustomerDTO Customer { get; set; }
public virtual List<EquipmentDTO> Equipments { get; set; }
}
As you can see, there is one customer as complex data and multiple equipments.
On the client side, can we store complex data like this in the nosql offline store?
On the client side, can we store complex data like this in the nosql offline store?
According to your description, I have checked The Domain Manager from adrian hall's book. Also, I have tested the similar code, and the complex data could be stored in the SQLite offline store as follows:
For offline Sync, when pushing local Job table to the remote, the relationships Customer and Equipments need to be ignored by the server-side as follows:
// For incoming requests, ignore the relationships
cfg.CreateMap<JobDTO, Job>()
.ForMember(job => job.Customer, map => map.Ignore())
.ForMember(job => job.Equipments, map => map.Ignore());
As Existing Table Relationships with the MappedEntityDomainManager states for syncing the Job table:
Customer and Equipment data all comes down as one record. This has a side effect of ensuring that the Customer and Equipment data is read-only. You can only update the information in the Job table.
Also, as Adrian Hall mentioned that he prefers handling tables individually and handling relationship management on the mobile client manually. This causes more code on the mobile client but makes the server much simpler by avoiding most of the complexity of relationships.
Yes, why not.
Just follow this document to using off-line store
https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-offline-data
Related
Suppose I have the following example Resource Model defined for API Create/Read/Update/Delete interactions involving the Customer types:
public class CustomerModel
{
public string Address { get; set; }
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Url]
public Uri Website { get; set; }
public DateTimeOffset WhenCreated { get; set; }
public DateTimeOffset WhenUpdated { get; set; }
}
Id, WhenCreated, and WhenUpdated are metadata to be generated by the underlying data repository and as such, if the customer adds them to a request they should not be kept (Id for example, would be specified in the URL so no need to include in the request body). However, these values are still important to the client.
Is there a simple approach to ignoring these metadata attributes if sent in the client request? I would expect this in the form of an attribute but have not found anything promising for .NET Core 3.1.
The JsonIgnore attribute would make sense but it wouldn't serialize the values in responses either.
I could create a separate model only used by clients for requests but this seems redundant, especially because it will require new mapping profiles. However, if using something like Swashbuckle for API documentation this could be the best approach since the class documentation wouldn't represent those as valid properties for requests.
I could add some logic to remove those properties in the business logic layer but that would likely involve another request to the database to retrieve their original values so it isn't ideal.
Thank you!
I was playing with the azure Document Db and came accross a problem or rather confusing about Ids. I know that DocumentDb generates a "lowercase" "id" property for every document, this is fine with me, but I cant seem to figure out how to get this "id" when using the .net client. my code looks like below
public class Company
{
public Guid Id { get; set; } // this somehow does not get mapped to the "id" in the document.
public string Name { get; set; }
public string Address { get; set; }
}
so when i query like
client.CreateDocumentQuery<Company>(collection.DocumentsLink).ToList();
the id property is not mapped. I think I havent understood the ID concept in document db and how it maps to your entities properly.
Any help is much appreciated.
Try changing your company entity to
[JsonProperty("id")]
public String Id { get; set; }
This will load the documentdb generated Id, into the id field.
Let me know if that doesnt work.
I have a movie entity and a actor entity, these 2 entities have a many to many relationship, so I've mapped it as ManyToMany(x=>x.Movies) and ManyToMany(x=>x.Actors) but i'd like to have the character the actor played on the movie, it should stay on the MoviesActorsPivot as a new column
But how can I do that using the Fluent Nhibernate Mapping in a way that I could get and save the data as easy as nhibernate does?
Not creating the pivot table manually and making the HasMany(x => x.MoviesActorsPivot) on both sides and managing the association by my own.
Edit:
Or if I map it creating the HasMany(x => x.MoviesActorsPivot) on both sides, how would i manage to insert and get al data like all movies from an actor or all actors that act on a movie, getting all the characters names?
The answer is:
NHibernate native many-to-many mapping does not support any additional setting on the pairing table
But, it could be replaced with a pairing object being first level citizen
public class MovieActor
{
public virtual Movie Movie { get; set; }
public virtual Actor Actor { get; set; }
... // more properties here
public virtual int Rating { get; set; }
}
public class Actor
{
public virtual IList<MovieActor> Movies { get; set; }
}
public class Movie
{
public virtual IList<MovieActor> Actors { get; set; }
}
That would be standard HasMany and References mapping. And the queriyng later will be more easier
Also check these:
Nhibernate: How to represent Many-To-Many relationships with One-to-Many relationships?
nhibernate many to many with multiple table
many-to-many with extra columns nhibernate
I'm using ASP.NET MVC 3 and my repositories are using ADO.NET with stored procedures to fill my domain objects. I'm not 100% sure where certain objects should be filled. For example I need to fill the User property based on the UserId retrieved. What is the best approach to do this? For each domain object I have a repository and a unit of work object that manages the transaction and connection.
public class Comment
{
public string Post { get; set; }
public int UserId { get; set; }
public int ParentCommentId { get; set; }
List<Comment> Comments { get; set; }
public User User { get; set; }
}
Any insight would be greatly appreciated.
Without knowing more about your domain it is difficult to answer the quesiton. This is more related to Domain Driven Design than to the MVC framework. The concept you need to investigate is called Aggregates in DDD. An aggregate is a collection of model objects that logically fit together. One of the models in the aggregate would be a root object that handles the other model objects in the aggregate including persistence.
You would have a repository for each aggregate root and not for each model object. I would recommend going through the free downloadable minibook from InfoQ called Domain Driven Design Quickly. The author has summarized the excellent Domain Driven Design book by Eric Evans in this minibook.
Part of my project is to persist data from another source. In this case we have an SAP data source that we will need to pull data from. I need to take the data from SAP and map it to entities I have in my application. Here is an example of an entity I have in my application:
public class Project : BaseEntity
{
public string Name { get; set; }
public string ProjectNumber { get; set; }
public string Description { get; set; }
public string CreatedBy { get; set; }
public string ModifiedBy { get; set; }
public string Currency { get; set; }
#region Navigation Properties
public virtual Address Address { get; set; }
public virtual CompanyCode CompanyCode { get; set; }
public virtual ICollection<Contact> TeamMembers { get; set; }
#endregion
}
As you can see, I have child objects that I map from SAP as well. I need some advice on the best way to insert and update my entities. I am struggling with knowing when to add (insert) entities to my context and when to attach (update) them, because SAP doesn't have knowledge of what my application may or may not have. I need to guard against duplicates, too. For example, should I perform a lookup of each child entity in my parent entity to see if they exist before I apply them to the parent? Then, add / attach the entire parent object to the context or handle each entity separately while still maintaing their relationships?
Yes you must manually test everything to make correct decision what must be inserted, updated or deleted. Depending on the application you can use some more complex queries to reduce number of round trips to the database - for example you can use single query with Contains to load all TeamMembers needed for processed Project or you can load Project with including all related data if you also need to test if project exists.
I did large synchronization application before and I end up with pre-loading all entities at the beginning with few queries and working completely in memory.
Don't forget to use DbSet's Local property or Find method to take advantage of already loaded entities.
You can also use some custom stored procedures to improve performance of this operation.