Creating .edmx file programmatically - asp.net

Is there any way to create edmx file programmatically without configuring manually.
My requirement is like this: I have to create a website dynamically. In that website I have to use EF files. ie. I have to create edmx file programatically and not manually. I have the Database name, connection string, server name, username, password and all with me.
Is there any way to achieve this?

I have found the solution. The following link helps those who want to create edmx file programmatically in VS 2012.
https://bitbucket.org/cincura_net/edmgen2/
This is a new thread. Will be helpful for those who found EdmxGen2 is not compatable with vs 2010.
Thanks,
Sujith.S

Yes, you can have a look at edmgen2.exe for info on how to create the edmx programitically. http://archive.msdn.microsoft.com/EdmGen2

Related

Errors when including Entity Data Model across referenced projects

Decided to take a dive into recreating a website so that it's an ASP.NET MVC web application. We were originally using the Entity Framework for it, figured to still use it since it works nicely enough. When doing some reading, noticed the there is no such thing as the App_Code/ folder for MVC applications, and that most people were creating a class library for their needs like that. So what I ended up doing was creating my MVC application and a class library, both in the same solution, and the MVC application was referencing the class library. The class library has my EDMX Entity Data Model file in it since some of my classes reference it and I thought that it would be easiest to have it in the library to reference. So here is a picture to what my solution layout is. But when I build and run the website, I get an error on a page that would reference the Entity Data Model. Here is a picture of what the error is.
So I thought, what if I placed the EDMX into my models folder since the error looks like it's complaining about not finding the entities. Here's a picture of my solution now with the move. But now, I'm getting a different error (picture). I'm kind of at a loss as to where to go from here. Is the way I have everything laid out and designed the proper and most efficient way to do it? If not could someone give me some advice?
Thanks, it's really appreciated!
Yes, you should be able to have the edmx in a class library and reference if from your main project. The first error is likely due to an incorrect connection string (check this blog post) but you may also have changed the build action of the edmx file somehow, make sure it is "Entity Deploy".
The second error is probably because you copied the edmx from your class library into the Models folder and it is still referencing the old namespace. To fix that, open the edmx in designer view and click on the background. One of the properties in the property window is Namespace, make sure that's set to the new place you want to keep it.
Edit:
Some things to try:
Clean and rebuild the project
Delete the Temporary ASP.NET Files folder referenced in the error message
Double check your cshtml files for old references to URG_MVC.Models namespace. For example, the line in the error should be IEnumerable<URGLibrary.Proposal>
Right click the edmx file and select Run Custom Tool to regenerate the model files

I've a sql database file I want to use asp_regsql.exe tool to put asp.net membership provider

I've a sql database file I want to use asp_regsql.exe tool to put asp.net membership provider
The main problem that I can't use the asp_regsql.exe to add the tables that I need ,
I tried various of connections ,
If some one got a CREATE sql file that contains the membership table construction it would help ,
Thank you in advance
Check out this tip I have written in code project. Simply, you can call the following once:
System.Web.Management.SqlServices.Install("YOUR_DATABASE", SqlFeatures.All, "YOUR_CONNECTION_STRING");
You can find the SQL script # %WINDOWS%\Microsoft.NET\Framework\v2.0.50727\InstallCommon.sql
Source: https://web.archive.org/web/20211020203214/https://www.4guysfromrolla.com/articles/040506-1.aspx

how to find local image in asp.net project?

I have a solution contains a web project named "Web", and a dependeny class library project named "Service". I use the ASP.Net MVC2 to build up my solution. As you know, there's a Content folder storing images and css files under the web project. Now I need to get the stream reference of "Content\Images\anon.png" in one class of my "Service" project.
I tried
var result = new FileStream(#"Content\Images\anon.png", FileMode.Open);
and press F5 to debug, but it cannot find the file and throws an exception.
I am using VS2010, please tell me how can I access to this image. Thanks very much.
Can you try
Server.MapPath("~/Content/Images/anon.png")
You can use System.Web.VirtualPathUtility.ToAbsolute("~/Content/Images/anon.png"); or RequestContext.HttpContext.Request.MapPath as well
Visual studio makes it to a temp directory for your web app, not your solution folder/ If you publish your app on a IIS server, the Server.map will be correct.
Because it is searching for the file in Debug\Content\Images\ . Are you sure the images is really there? Make sure that your file is in that path.

update .dbml file

How to update .dbml file after making some changes in the database.
There's no built-in way to sync the dbml file/datacontext with the database after making changes (besides regenerating the entire dbml file by removing all or a selection of the entities and re-dragging them, or by using sqlmetal as suggested by other replies), but there are third-party tools that add refresh functionality to the Visual Studio L2S designer.
One such tool is my add-in, Huagati DBML/EDMX Tools. You can download it from http://www.huagati.com/dbmltools/ and get a trial license if you want to take it for a test spin.
Jim Wooley has a summary various Linq and Linq-to-SQL tools here:
http://www.thinqlinq.com/default/LINQ-Tools.aspx
...and Damien Guard has a list of tools/resources for L2S here:
http://damieng.com/blog/2009/06/04/linq-to-sql-resources
The only way to do this is to delete the objects from the dbml interface, and re-add them back. Make sure that you hit Refresh in the Server Explorer panel after making changes to the database so that Visual Studio picks up the latest changes to the database when it creates the objects in the dbml.
SQLMetal is the tool you want. It installs with Visual Studio as part of the SDK. For most dbml, however, I've found the delete/re-add technique to be a bit more expedient and reliable.
There is no way to auto refresh the DBML to match the database. If you have added new tables to the datbase you can simply drage them into the designer window. If you have added or changed fields on existing tables or altered foreign keys/relationships, your best bet is to manually edit the classes and properties in the DBML file. ~You can delete them and the drag them back in from server explorer which will refrech them from the datbase but you will lose any custom modifications you have made such as changing properties from public to protected or setting up inhertance or other things.

Subsonic SQLite Multiple Files

I have an application that must be accessed for many users.
To optimize the performance I intend to store each user profile information at a independant database file.
I need everytime a user login the application, to setup a new provider linked with his own database.
All databases have the same structure. So while querying user the commom generated DAL classes must switch for the database file relative the the user.
Is there a way for configure SubSonic for doing that switch at runtime?
Thanks.
Well, assuming we 're talking about SubSonic3:
I have made a patch for this and logged it as an issue in the SubSonic Templates project on github, where the source is available. You can find the issue (and a link to the code) here.
After you apply the patch, you will have a new DefaultDataProvider property which does exactly what you want. Use it like this (e.g. after a user logs in):
YourSubSonicGeneratedNamespace.YourDatabaseName.DefaultDataProvider =
SubSonic.DataProviders.ProviderFactory.GetProvider(
"your connection string here",
SubSonic.DataProviders.DbClientTypeName.SqlLite);
And you 're good to go.
For SubSonic 2, this answer sounds like what you want.
With subsonic 2 I use an approach where I inject the provider at runtime rather than loading it from the app.config file.
Look at my answer here: Subsonic in a VS2008 Add-In woes
Instead of just using one provider you could create one for every user who starts the application and change the default provider as needed.

Resources