function import in entity framework - visual-studio-2010

As the MSDN says
Do one of the following from the Model Browser:
Open the Stored Procedures folder (in the storage model information) and double-click a stored procedure that does not have a corresponding function import.
- OR -
Right-click the Function Imports folder (in the EntityContainer node of the conceptual model information) and then select Add Function Import.
The Add Function Import dialog box appears.
How can I do function import if my db contains hundreds of sps. Should I go to each sp and do the steps above :( .. It makes no sense.

I have a very large Entity Framework model and I use the Huagati DBML/EDMX tools. It was able to bulk add new tables, views and columns that were in the database but not in the EDMX. It saved a lot of manual work. I haven't used it for stored procedures but it looks like it supports it. Even better, they have a free trial so you can always give it a try to see if it will work for you.
Edit: It also sounds like they have made some improvements to this in the latest version of EF - the June 2011 CTP. This blog post states:
There are several new features for the Entity Framework Designer
within Visual Studio:
[...]
When you import stored procedures using the Entity Model Wizard,
you
can now batch import your stored procedures as function imports.
The
result shape of each stored procedure will automatically become a
new
complex type in your entity model. This makes getting started with
stored procedures very easy.
If you don't want to use a CTP, this blog post says they might have the official version out next month.

Related

Dynamics CRM 2015 Import values

I am using Microsoft Dynamics CRM 2015 on-premise version.
Im importing my solution to an other organization with custom entities and workflows.
I created a workflow to do some work depending on the type of the inserted queueitem.
My issue: Some conditions in my imported workflow are not supported in the new organisation (only the conditions on the custom entities are not supported and are replaced by empty brackets)
I think the custom entities IDs are not imported with the same values, so, the CRM does not recognize these custom entities condition.
Try exporting and importing the customization in two separate solutions.
In the first solution include the entities and optionsets you wish to import. Export the solution from the old environment, import into the the new environment and publish.
In the second solution include the workflows. Oncce again export the solution from the old environment, import into the the new environment and publish.
When you point to an entity inside a workflow, it will retain the GUID.
If you export/import the workflow, the reference will be lost because that specific GUID won't exist in the new environment.
The issue is indeed that the GUID values of the records referenced in your workflows are passed trough the solution but doesn't exist in your target environment.
You can either:
Modify you workflows, instead of (for example) Primary Entity Opportunity / Account / Equals / Contoso use Related Entity Account / Account Number / Equals / ContosoNumber
Import the data referenced in your workflows by keeping the same GUIDs. This is slightly more technical:
First, you need to export the data from your source organization (either SQL or Export to Excel with reimport enabled)
Then convert this file to csv while keeping the id value embeded
Reimport the file with import wizard and mapping the GUID column

How do you build OData IEdmModel from Entity Framework model

The title says it all really. I've found several blogs with different ways (serializing the EF model to XML and then de-serializing again to the IEdmModel was one) but they're all based on old version of the OData package.
Serializing is the only way.
Example.
Relevant work.
I've ranted about this a few months ago. AFAIK nothing changed since then, and I personally don't expect them to change too much. The short story is that as of September 2012, there is no plan to use EdmLib in EF, nor is there to use EF's code in other projects.
How much should we align with OData’s EdmLib?
Not worth adopting code
Cost of implementing SSDL & MSL
Freedom to evolve our API independently
Look at aligning names of types and properties where appropriate
If your DbContext is being built from a database-first approach the given answer will fail giving this error:
Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.
After some time messing with this I have found an appropriate solution. Basically you grab the CSDL resource from the assembly containing the DbContext in question and parse it using the Microsoft.Data.Edm.Csdl.CsdlReader.TryParse method. The resulting IEdmModel is valid containing the exact information given by EntityFramework when the model was built.
See here for an example with usage

Stored procedure in Entity framework with multiple parameters in mvc3

I am new in entity framework and mvc3.how can i execute Stored procedure in Entity framework with multiple parameters in mvc3.
This depends if you are using code first or not. I do agree with the folks above you could've probably easily researched this but I'll provide an overview here so it's all in one spot to review as there are several options to consider.
With code first in the latest version of EF 6 Beta, you can execute stored procs as part of code-first as described in the docs here
Prior to EFv6 you could use the following to execute a proc in your code and map to an entitycontext.Database.SqlQuery<YourEntityType>
If you aren't using code first, you can map in the designer as explained by Julie Lerman many places, but one easy link is here

The Entity you are trying to import is not the same as the one existing in the database even though it has the same name

when trying to import customizations for a specific entity I get an error saying that I can't reuse system queries for a custom entity.
The error in the title appears in the detailed CRM trace:
Could not import a Saved Query {C9771189-0CB3-E111-A93D-00505699001D} for ObjectTypeCode 10010 because this is a system Saved Query. The Entity you are trying to import is not the same as the one existing in the database even though it has the same name.
the id of the query is the one in the source customizations.
Both the source and target entities seem to have the exact same queries, with the same names.
Google hasn't been able to offer much on this.
Can anyone shed any light on the subject?
Is your source environment upgraded from v3.0? If so have you applied the hotfix (or latest rollup) mentioned in this KB article to both servers?

Remove schema from linq datacontexts (dbml)

When I add stored procedures to a linq datacontext, by default visual studio prefixes the stored procedure with the sql schema that it is in. Is there any way to stop this? In our environment, the stored procedures may be moved to other schemas over time, and we will default the schema based on the sql user used to connect. Do I have to do this manually or can I somehow turn off the schema prefixes?
There doesn't appear to be any means of removing the schema from LINQ-to-SQL mapped stored procedures using the designer. All procs are mapped including their schema name, which (to be fair) is probably a good thing for most applications. And as with most things LINQ-to-SQL, change your database at your own peril. Too many database changes required LINQ-to-SQL dbml updates & rebuilds.
Digging deeper, the schema name is stored in the backing dbml XML file, and is then included in the generated designer.cs file which contains the functions / methods which are called.
// dbml
<Function Name="dbo.MyProc" Method="MyProc">
// designer.cs
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.MyProc")]
public int MyProc()
If you manually edit the dbml XML file to remove the schema & save within Visual Studio, the code will be regenerated like this:
// changed dbml - removed the dbo schema
<Function Name="MyProc" Method="MyProc">
// the resultant generated code in designer.cs
[global::System.Data.Linq.Mapping.FunctionAttribute()]
public int MyProc()
Which worked for my account, logging in with dbo as default schema. I'll leave the testing up to you.
This might be a workable solution - the visual designer still works like this, other items can be added etc without breaking the schema-less function, and the function itself doesn't cause the designer to complain. Best of luck!

Resources