Does the entity framework provides an API for .net (c#) to generate models from an existing database? I don't want to use EdmGen.exe, because a direct integration would be nice.
Maybe even the code which is used by the EdmGen.exe provides some information, because they also have to use some API functionality.
This is needed, because i want to compile the models dynamicaly with roslyn at runtime, which is currently working pretty well with some demo models.
Thank you.
Related
I am building a new ASP.NET Core 5 MVC app. I want to use clean architecture as outlined in Microsoft's web app architecture ebook.
I am also studying eShopOnWeb sample application available here :
https://github.com/dotnet-architecture/eShopOnWeb
What I understand from the ebook and sample app is - EF Core entity classes (say Customer, Product, Order) will go inside ApplicationCore project's Entities folder. The DbContext will be in Infrastructure project.
My confusion is: is it alright to add data annotation schema attributes such as [Table], [DatabaseGenerated], and [Key] on these entity classes inside ApplicationCore project? If not, where should I add these data annotations?
Any advice in this regards is highly appreciated.
Thank you.
In the example of eShopOnWeb they separate Entities and configuration models. So, that means to have clean architecture you don't need annotations directly in these Entities.
You can use FluentAPI, as they used as well in the Infrastructure/Data/Config directory.
So, if you have a separate project for DataContext that is the best location for describing your entities with FluentAPI in this case.
More information about FluentAPI:
https://learn.microsoft.com/en-us/ef/ef6/modeling/code-first/fluent/types-and-properties
I am new to Silverlight and am developing an ASP.NET web application that requires a Silverlight project to record webcam audio/video streams.
The solution consists of a library project containing business entities such as [User], [BillingInfo], etc., and an ASP .NET Web Application.
Since Silverlight does not support EF, how can I use the strongly-typed entity objects from within Silverlight? I do not need access to the Context object but will require access to Entity classes.
I use Code First so have to mark Entities with Annotations which Silverlight will not recognize since the DataAnnotations assembly is not referencable. Switching to model-first is also an option (albeit less preferable) if required.
Has anyone dealt with a similar scenario? What is the best way to get strongly-typed entities in Silverlight. Any articles or references would help as well. Thank you.
Technologies (upgrade is an option if required):
ASP .NET Web Application (.NET 4)
Entity Framework 5
Silverlight 5
I would recomend giving WCF RIA Services a try. This will simplify the data access for your application and provide you with strongly typed entities on the Silverlight client side.
Silverlight works very well with entity framework!
You could directly consume your entity through webservices as describe in this blog: http://geekswithblogs.net/berthin/archive/2011/05/29/ado_net_entityframework_from_silverlight.aspx
Or as Dave suggest, you could combine RIA services and Entity Framework, so you could use annotation http://blogs.msdn.com/b/brada/archive/2010/03/15/silverlight-4-ria-services-ready-for-business-exposing-data-from-entity-framework.aspx
The combination of Silverlight and Entity Framework create a really powerfull ready to use business logic.
I've been looking into using and MVC C# frontend to a Caché database backend. After looking around for a while i haven't been able to find an effective way of connecting the two together (via .edmx model generation). I know I'll need a database driver for Visual Studio 2012 to do this but i don't know where to find it.
I've been developing a few apps using MVC technology and want to keep following suit instead of resorting to using their .csp based technology.
Hopefully somebody can help with this.
Take a look at the Cache Managed Provider for .NET documentation:
http://docs.intersystems.com/cache20121/csp/docbook/DocBook.UI.Page.cls?KEY=GBMP
The Managed Provider functionality specifically allows you to access Cache data from within .NET programs. It's not going to be as nice as using, say, the .NET Entity Framework to do data access, plus you'll have to take InterSystems' code example with a grain of salt since they are pretty simplistic, but this should be what you need.
You can use an ORM framework like Entity Framework or NHibernate to get access to Intersystems Cache so the database can be separated nicely in the data layer. I managed to make NHibernate works with Intersystems Cache works. Have a look at here if you are interested.
I have a requirement in which in order to make an application extensible and reusable, I have to create a provision through which a user would be able to provide a business object structure (the fields, their types, etc.) through an XML file and using that structure the UI (i.e. the controls and the complete page), the data updation methods (CRUD) and the database (i.e. the tables and the SPs) can be dynamically generated automatically in order to cater to the business object.
I've 'only' heard about Entity framework, LINQ, etc. but do not know if they'd be any helpful in achieving what I wish for.
Any suggestions or guidance on how to approach towards this design goal would be highly appreciated.
Thanks a ton!
You may want to take a look at ASP.NET Dynamic Data. It still requires you to provide it an Entity Framework model, but you can dynamically generate the model using the EdmGen.exe tool.
Here is some info about each... Follow the links more more detail.
ASP.NET Dynamic Data
ASP.NET Dynamic Data provides a framework that enables you to quickly build a functional data-driven application, based on a LINQ to SQL or Entity Framework data model. It also adds great flexibility and functionality to the DetailsView, FormView, GridView, and ListView controls in the form of smart validation and the ability to easily change the display of these controls using templates.
EdmGen.exe
EdmGen.exe is a command-line tool used for working with Entity Framework model and mapping files. You can use the EdmGen.exe tool to do the following:
Connect to a data source by using a data source–specific .NET Framework data provider, and generate the conceptual model (.csdl), storage model (.ssdl), and mapping (.msl) files that are used by the Entity Framework . For more information, see How to: Use EdmGen.exe to Generate the Model and Mapping Files.
Validate an existing model. For more information, see How to: Use EdmGen.exe to Validate Model and Mapping Files.
Generate a C# or Visual Basic code file that contains the object classes generated from a conceptual model (.csdl) file. For more information, see How to: Use EdmGen.exe to Generate Object-Layer Code.
Generate a C# or Visual Basic code file that contains the pre-generated views for an existing model. For more information, How to: Pre-Generate Views to Improve Query Performance.
Check out lightswitch:
http://www.microsoft.com/visualstudio/en-us/lightswitch
commercial product: Enterprise Elements Repository
In EJB 3.0 you can write your domain objecs, then convert them into entitities (adding #Entity attribute, etc.) and underlying JPA mechanism (let's say Hibernate) can automaticly generate db schema. What's better it will also update db when you update you domain model in Java code.
I'm looking for equivalent of that functionality on .NET platform. Is is possible with ADO.NET Entity Framework?
DataObjects.Net also automatically generates and upgrades database schema according to domain model. But the most interesting thing is how to upgrade stored data if model and database schema are changed. Is it possible to do it on entity level, rather then using low-level SQL?
Mindscape LightSpeed supports this - full schema round tripping with model first or database first development. It is a commercial product but there is a free version for small databases.
As mentioned, Entity Framework will add some of these features in their next release but that is some time away.
Details of the LightSpeed designer with the model first support
Active Record is the way forward! You mark up your objects with attributes and from there you can generate the database schema or the database itself. There is also a tool called Active Writer which allows you to draw the models and it writes the codes with the correct attributes for you.
It is essentially a wrapper for NHibernate but it makes things a bit easier as you do the mapping on the objects rather than in XML documents.
We have used this on several projects and found it to be a fast way of implementing complex systems.
Yes - in the future :-) The current Entity Framework doesn't support the "domain-first" approach - but the next version (EF v4) will. This will ship with .NET 4.0 / Visual Studio 2010 - but don't ask me, when! I don't know (neither does Microsoft).
Marc
NHibernate is a .NET port of Hibernate, and I think it includes tools for generating database schema for your entities.
There are third party frameworks that do this in .NET today.