I am deciding how I should create an entity which I pull from a 3rd party api. The concept of my entity requires two API calls, one of which pulls the unique data about the entity, and the other which gives me a full schema of all possible data that could belong to an entity.
I've already written a repository for the entity, but where does the schema map fit in the domain layer if I'm only going to grab it once?
How should the entity hold this schema data?
I'm not familar with the mapper pattern, but does that seem like this is the right use case for it?
If you have schema data and then data then you're dealing with an entity with dynamic properties, akin to a dictionary or hashtable, but with validation.
You could treat the schema data as an entity of its own, that provides the knowledge level to instantiate and validate entities, which lie on the operational level.
Take a look here (pdf) for many related patterns.
Related
Often web application have a database. Let say in this database there is for a table "user" . What I see often is that the developer creates a ORM class to get the data out of the database. "user" class for example is just a container for data from the database.
That's not what I do. "user" is a encapsulation of the behavior of a user. All code that does something with the user is inside the "user" class. ORM is added because the data is often stored in the database. I always define 2 classes: A "users"/"userlist" class (collection of users) and a user (individual user). The "users"/"userlist" class also representing the table and "user" representing the individual records (for example checking of the password is correct).
What I have noticed that many ORM (like ActiveRecord) system don't make the distinction between table and individual record. There is just one class "user".
My question is as follows:
Are there any ORM systems which makes a distinction between table and record (like the users/user in above example)
How do you use ORM, only for accessing data from database or for real oop.
If a ORM doesn't make distinction between table and record, where do you place code which processes multiple records
What do you think is a good way to combine oop and ORM?
An ORM class represents a single record and the entirety of those records represents the table. I don't think there is a need for a class that represents the table. What you commonly have in edition to the individual records is a service (e.g. UserService) that deals with operations on multiple objects.
Should I store ref id to child Poco or only ref object in Model when using micro ORM like Dapper (in Repository)?
I think that if I store both there will be synchronization issue when updating root object.
For example:
Class Boat
+Id
+LakeId
+Lake
Class Lake
+Id
+Name
What If some changes LakeId ? Lake will be in invalid state!
What if someone changes Lake and live LakeId? LakeId will be in invalid state.
I thing that synchronization of those two properties will be an additional unnecessary complexity. Changing LakeId will require to get new Lake poco from db.
How do you deal with this in your projects (only using micro ORM like Dapper or PetaPoco)?
Any micro orm is just a data mapper on steroids. It doesn't care what sql you write, it just tries to map the query result to an object. Any insert/update helpers just make it easier to do that operation without messing with sql.
Your concerns have nothing to do with the micro orm. You simply have to put a foreign key constraint on LakeId. I don't really understand why you have both LakeId and Lake in Boat. You need to get the db schema straight first, then the object (POCO) you need for mapping the query result.
I'm trying out Microsoft Master Data Services and I would like to add data to the database programmatically. I'm starting to get the model/entity/member structure but I'm not yet sure. If you have a nice explanation for this structure, please share.
Say somebody added a new employee in an ERP system and I would like to send that to the MDS. How would I do that? Is the data that I want to add a new member? Because if I look at the following information (http://technet.microsoft.com/en-us/library/hh230995), the only way to import data is through entities?
Thanks in advance for any useful information about this!
Lets start with the basics.
Entities in Master Data Services (MDS) are roughly analogous to tables in a regular database.
Every entity must live in a model.
A model can contain any number of entities.
The Metadata* methods you see on that page can be used to create, read and update models and entities. Once you have modeled your ERP tables as an MDS model, you can use the EntityMembersCreate API (with the relevant model/entity information) to create a member (roughly analogous to a row in a table). You can use EntityMembersUpdate to update members and EntityMembersDelete to delete them.
Another way to get large amounts of data into MDS is by using Entity Based Staging. Entity Based Staging allows you to use tools like SSIS to get bulk data into MDS. A good primer here: http://msdn.microsoft.com/en-us/sqlserver/hh802433.aspx.
I hope this helps. Feel free to ask more questions.
I like using a generic data-access-object that classes in my model inherit from. Each class has a one to one relationship with tables in the database.
We're using SSIS to replicate data from our CRM (as well as other data sources) into our MDS (for the time-being). If you're not familiar with the tool, I'd recommend in terms of moving data around - it's relatively easy to pickup the basics. If you go this route, here's a great resource I followed to push data into our MDS system:
http://www.sqlchick.com/entries/2013/2/16/importing-data-into-master-data-services-2012-part-2.html
I have a complex iPad app moving to use Core Data. I receive data from a server which has foreign keys built into the various tables to represent relationships between tables (entities).
As I rewrite the app to use Core Data, should I maintain the foreign key structure and create my own accessors, or convert them to Core Data relationships or use both? Seems double the work. I already have the data to link two tables that I potentially need to maintain for data I send back to the server. Yet Core Data will create its own keys for relationships. It duplicates information and could get out of sync.
I could:
1. Keep the existing attributes to represent relationships between tables and write my own fetches as needed.
2. Build an object graph as I receive the data from the server and use core data relationships .
3. Use a hybrid, sometimes foreign key attributes and sometimes relationships depending on need.
Is there a typically approach used for Core Data applications receiving most of their data from a server?
If you are going to use core data instead of sqllite, then convert to Core Data. Remember, CoreData is not just a relational database. It is used to persist an object graph. Thus, the way you lay our your data structures may be quite different.
Typically, you may have more de-normalized data in a Core Data application, but really, you should remap your data as you want it to be used in your application. Then you will know the real answer. However, I do not think I'd leave foreign keys... I'd use relationships because that's how core data will fit best.
I'm getting data where the database is hidden behind a WCF service.
Is it possible to use Entity Framework in a scenario where I have custom objects coming from a web service?
(No access to the external database, and no current plans for insert/update/delete logic)
Starting with an empty EF model and adding an entity I get this error on compile:
No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer ..
Is it possible to make an entity this way, and fill it with data received from an object?
(In this case a WCF, but could also be a predefined model class/xml data)
If the web service retured a Customer object I could do something like this with a dataset:
Make an unbound table and do a loop through the customer properties adding them to a temp row, add it with tbl_Customer.Addtbl_CustomerRow(customerRow) to get my view filled.
thanks, nakori
Entities are object representation of your DB entries (see Object-Relationnal Mapping; ORMs). Given Employee and SalesOrder, two hypothetical tables in a DB :
Entity: entities are instances of Entity Types (e.g. Employee, SalesOrder), which are richly structured records with a key. Entities are grouped in Entity-Sets.
Taken from the Modeling Data at the Conceptual Level of Abstraction: The Entity Data Model section of The ADO.NET Entity Framework Overview. Perhaps it is also a good read to start using the EF.
As for comm through WCF, it is kindof supported, such that entities are fully serializable/deserializable. You may also want to know that you can generate entities from an existing DB, theres a wizard and everything.