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.
Related
I know that each time a user registers in my ASP.NET MVC application the ApplicationUser class is used to create the new record and put it in the database.
I was wondering if it's okay to add properties to that class for example I want the model to have a column in the database for DateOfBirth. Then use that class(model) directly in my application when I have to do some business logic things, database queries and similar stuff. Or is it more correct to create a new table in the database called let's say ApplicationAccounts, that saves the general info about the account. Each ApplicationAccount will be associated with a ApplicationUser(1 to 1 relation) and be somewhat of a buffer in the communication with the real accounts. Does that make sense?
I would go with the second option : create your own table, link them up in a one to one relationship using the UserID as a unique foreign key and then go from there.
One note here, it is perfectly normal for the model you need for the views to be different from the database model, this is because your db model can hold a lot of data that your view doesn't actually need. You might want to consider having separate models and use something like Automapper for a quick translation from one to another.
I'm trying to develop a .net4 application using c#, wcf and entity framework. My first idea was to pass the EF generated objects through wcf (first with the default entity objects, then with the POCO entities), but I soon got several connection problems (connection is closed) due to non serializable objects in the generated entities. I ended up writing several data-only classes to host the data queried with EF, but now I miss the role of the EF with WCF. I guess I'm doing something wrong, so how do you send data through wcf using EF? What is the point of EF? Wouldn't it be easier to write stored procs and standard ado.net...?
Entity Framework is just a data access technology. You can create a data access layer which talks to your database and return the required data using Entity framework and then plug that to your WCF service so that your WCF service will get the data. You can use the same data access layer with any other consumers ( a Silver light application, A Windows form project or an MVC application). The advantage of using Entity framework is that it will load the data to your domain objects (your POCO classes) so that you do not need to do it manually yourself. In the case of Stored proc, you need to execute the stored proc, Iterate thru the DataReader/ DataTable the fill your objects. For this you have to write code. If you use Entity framework, EF does this for you so you can save some dev time.
You should clearly logically seperate your project so that there will be a data access and a consumer which consumes the Data Acccess layer( your WCF service).
I have SQL Server database and would like to use LINQ to Entities and wrap it with WCF layer and expose it to client. (typical N-Tier architecture). ALso would like to have Persistence ignorant option and also would like to have an option ignore certain fields (sensitive information) in database from serializing it to client.
So what would be best approach for using Entity Framework with Persistence Ignorance, Self Tracking with WCF Support. I could find T4 template with either Self Tracking or Persistence Ignorant.. But everything bundled as single package.
Any help in this would be greatly appreciated.
STEs don't allow any projections - you must expose your entities in their exact form. If you want to hide some fields you must abandon STEs and create your own DTOs (data transfer objects) exposing only subset of your entities data. Once you use DTOs you must manually handle all change tracking.
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.
I'm using S#arp Architecture (which uses NHibernate). I have some entities mapped to tables in one database and others mapped to a different database. Disclosure: Databases already exist so i can't do model first.
How do I configure this to work?
EDIT: Would the SchemaIs method in Fluent NHibernate be the recommended approach to map an entity to a table in a different database? I believe this is possible via NHib's xmp mapping files too.
You should use NHibernateSession.AddConfiguration instead for additional database. The call to NHibernateSession.AddConfiguration goes immediately under NHibernateSession.Init(). An explicit session factory key will have to be defined for the second initialization.
The whole process is explained here in detail.
https://github.com/sharparchitecture/sharp-architecture/wiki?Page=FAQ
The way I have done this is to initialise multiple NHibernateSessions in InitializeNHibernateSession within global.asax.cs using multiple nhibernate config files. I then used [Transaction("nhibernate.dbname")] (dbname being names assigned to WebSessionStorages) in the controllers against each appropriate action method.