Loading a schema created using Visual Studio DataSet Designer - visual-studio-2010

I have a simple DataSet with two DataTables which was designed using the VS10 DataSet designer, and I'm trying to read in it's schema file in order to initialize a dataSet I want to use in a WPF program. This is the code to initialize the DataSet:
private DataSet currentMeasurement;
private void CreateDataSource() { // initialize DataSet from schema
currentMeasurement = new DataSet();
currentMeasurement.ReadXmlSchema("MeasurementFile.xsd");
}
where MeasurementFile.xsd is the file created by the DataSet designer.
However, VS is throwing the following error upon executing the ReadXmlSchema line:
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: The invocation of the constructor on type 'MeasurementSet' that matches the specified binding constraints threw an exception.
The CreateDataSource method is called from the MeasurementSet constructor, so the error information seems fairly useless to my eyes.
Why am I unable to read in the schema?

Related

Filenet Change Document Class

I'm trying to change class for a given document and below is the code that I used
Document p8Document = Factory.Document.getInstance(p8ObjectStore,
oldDocumentClassName, new Id(documentId));
p8Document.changeClass(newDocClassName);
p8Document.save(RefreshMode.REFRESH);
Upon executing the code, I can see that document class is being changed successfully. Now the problem is if I run the code again for the same guid, the below line fetches the document again with the old document class name.
Document p8Document = Factory.Document.getInstance(p8ObjectStore,
oldDocumentClassName, new Id(documentId));
By using getInstance, you are not asking the server to verify the existence of the object. Use fetchInstance instead.
From Instantiating Objects
The getInstance methods are used to instantiate an object that references a server object that is assumed to already exist. The existence of the object is not verified on the Content Engine server, and no round trip to the server is made until you perform a function on the object
getInstance is a way that you can setup an object while avoiding a trip to the CE server.
The fetchInstance methods instantiate an object by first making a round-trip to the Content Engine server and retrieving ("fetching") property values.
fetchInstance actually will retrieve the object from the CE server.

Entity Framework 5 - Invalid column name - Reverse Engineer Code First

Using Entity Framework 5, Visual Studio 2010 with the Entity Framework Power Tools (Beta 2) extension.
Here is my database table structure:
I used the Reverse Engineer Code First function of the aforementioned extension, which generated the POCO classes and some 'mapping' files (not sure if that's the formal parlance) and a single DbContext-derived class. Other than the change I describe next, all of these generated classes are as-generated by the power tool.
In the Category.cs file, I added the following code to help flatten the object graph a bit:
private ICollection<Product> m_Products = null;
public ICollection<Product> Products
{
get
{
if (m_Products == null)
{
m_Products = new List<Product>();
foreach (var categoryProduct in CategoryProducts)
{
m_Products.Add(categoryProduct.Product);
}
}
return m_Products;
}
set { m_Products = value; }
}
I get the following exception, which I know must have something to do with the mappings, but I just can't quite figure this out.
Unhandled Exception: System.Data.EntityCommandExecutionException: An error occurred while
executing the command definition. See the inner exception for details.
---> System.Data.SqlClient.SqlException:
Invalid column name 'Category_CategoryId'.
If I need to post more information, such as the specifics of the mappings, just let me know and I'll do it. I wanted to keep this as short as possible, but I realize I've omitted some things that, for those unfamiliar with the code generated by the tool, may leave one wanting for more details.
You've added a navigation property to your model and so EF is trying to map that to your database. "Code First" means your code model defines your database schema.
Try adding the [NotMapped] attribute to your helper properties to tell EF to ignore them.
In case you've created DB scheme automatically and you are not using strategies like (DropDatabaseAlways/DropDatabaseIfModelChanges) - other words: you are really in Reverse Engineering, it seems that you have to manually add column "CategoryId" on "Category" table.
In case, you don't want to work with the property (I mean in DB), you can use Data Annotation [NotMapped] or Fluent API modelBuilder.Entity<Category>().Ignore(x=> x.CategoryId)
Finally it is possible that problem can be in mapping. I don't know whether you are using data annotations or Fluent API but EF may automatically looks for some db column (logical behavior derived from the model) and can not find it. In this case I recommend you make a revision of the mapping.
The OP already solved their problem, but I've had a similar error with a different solution. So here it is in case others need it:
I was missing a navigation property on one side of a 0..1 relationship between entities. Once I added an appropriate navigation property to the entity that was missing it, the problem was solved.
A bit more details: I had two entities with a 0..1 relationship using a FK. Entity A (parent) had a FK to Entity B (child). The child entity B had a navigation property to entity A, but A did not have a navigation property to B. After adding this, the problem was solved.

Why my super simple ASP.NET Web API (mvc4)+Entity Framework 5 doesn't work?

I spent days to know the problems of my work, but no luck.
I created new MVC4 Web API project.
Add EF5 with my database (Project>Add>ADO.NET Entity Data Model>Create from database which is in Azure SQL).
Add two tables to edmx as below. And two *.tt files generate entities and model classes successfully.
I can see the breakpoint(result) gives query result normally.
But json gives abnormal stream without error message. (ie, http://localhost:41813/api/sheet/157 returns "157" which cannot download. in general, "157.json" is downloaded)
I copied properties in results to my handmade POCO-style class and it works.
What is my problem? I cannot use generated model classes to send data through Json.
I hardly find out problem because no error message and no debug step available after the result breakpoint.
The reason the serialization fails are yours Navigation Properties - while the serializer is trying to walk the object graph they result in circular dependencies.
For your simple sample to work you have few ways around it.
Remove Navigation Property Sheet from SheetDetail
Wrap your objects in ViewModel classes with Navigation Property Sheet omitted
Create a metadata class with JsonIgnoreAttribute and then attach it to your entity with partial class and MetadataTypeAttribute
Here you can find sample for third solution (sample makes some assumptions as I don't know your exact data types):
public class SheetDetailSerializationMetadata
{
[JsonIgnore]
public Sheet Sheet { get; set; }
}
[MetadataType(typeof(SheetDetailSerializationMetadata))]
public partial class SheetDetail
{
}
As #danludwig comment, http://www.asp.net/web-api/overview/formats-and-model-binding/json-and-xml-serialization gives all answers about my problem.
Add below code in Global.asax solves the problem.
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling =
Newtonsoft.Json.PreserveReferencesHandling.All;

CRM2011 - SDK 5.0.3 - Linq to CRM Entities Problem

I'm using crmsvcutil to generate early bound types. In the crm 4.0 days one was able to load related entites just by hitting the entity.ChildEntities property.
//Winvs.Next.Entities.CrmDataContext dc = new Entities.CrmDataContext(new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(
var cred = new System.ServiceModel.Description.ClientCredentials();
cred.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
//
using (var organizationServiceProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(new Uri(System.Configuration.ConfigurationManager.ConnectionStrings["CrmConnection"].ConnectionString), null, cred, null))
using (Winvs.Next.Entities.CrmDataContext dc = new Entities.CrmDataContext(organizationServiceProxy))
{
// This statement is required to enable early-bound type support.
organizationServiceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new Microsoft.Xrm.Sdk.Client.ProxyTypesBehavior());
//
foreach (var a in dc.AccountSet)
{
foreach (var c in a.contact_customer_accounts)
{
c.FullName.ToString();
}
}
}
When I do this with the latest CRM 2011 SDK version instead of loading realted entities I'm getting a NullReferenceException which gives me no further information about the issue.
foreach (var c in a.contact_customer_accounts)
What Do i miss? How can I load related entities with CRM2011 Linq?
I was having exactly the same issue as you. I saw those properties and was perplexed as to why they always returned null. They clearly were intended to retrieve entities for a particular relationship, yet they seemed to be "dormant."
It occurred to me that maybe the context object was not configured properly to lazy-load these "navigation" properties (to borrow a term from Entity Framework). So I started researching what I could about OrganizationServiceContext, and found this bit about its LoadProperty method:
If the property represents an association, link or deferred property, calling this method provides the client a way to lazily load related resources.
That sounded like what I needed, and one of the overloads takes an Entity and a Relationship as input. So, once you have an instance of an entity with one or more relationships, you need to ask the context to load the corresponding properties. Keep in mind, the entity must be attached to the context, either automatically (because you retrieved the entity via a context query), or manually using the Attach method.
I'm a little confused by your code because you're using a CrmDataContext object rather than an OrganizationServiceContext object. The code samples in the 2011 SDK use the latter, and the crmsvcutil will even generate a custom instance of OrganizationServiceContext with methods in the form of "[ENTITY_NAME]Set" (i.e. AccountSet as in your example). You may need to switch over to the newer context type.
So, using your example and assuming dc is now an instance of OrganizationServiceContext, it would look like:
Relationship contactRel = new Relationship("contact_customer_accounts");
foreach (var a in dc.AccountSet) {
dc.LoadProperty(a, contactRel); // Tell context to load entities from this relationship
foreach (var c in a.contact_customer_accounts) {
c.FullName.ToString();
}
}
It is a pain to have to manually load each relationship, but I can find no other way of activating those properties.
Note: To get crmsvcutil to generate a custom OrganizationServiceContext, specify the serviceContextName switch:
crmsvcutil.exe /url:<your_crm_url> /out:Xrm.cs /serviceContextName:XrmServiceContext
This would create a derived class named XrmServiceContext with accessors for all of the different entity types in your organization.
I really have no clue why this is the way it is but it turned out after some researching sessions that one has to use the xrm provided code customization assembly to generate the entity object model classes.
There is a SDK Version 5.0.4 sample provided which builds a sample console showing off how to generate and consume the entity classes in a way we're all used from the CRM 4.0 xrm days.
To make a long story short I post the crmsvcutil call here, for further information you should consult the sdk sample Walkthrough: Build a Console Application That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions http://technet.microsoft.com/en-us/library/gg695803.aspx
CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm\Xrm.cs /url:http://Crm/Contoso/XRMServices/2011/Organization.svc /domain:CONTOSO /username:administrator /password:pass#word1 /namespace:Xrm /serviceContextName:XrmServiceContext

Generate sequence diagram fails with VS2010 - Object reference not set to an instance of an object

Every time I try to generate a seqeuence diagram I get that "Object reference not set to an instance of an object" from Visual Studio 2010.
I searched google, found some people also posting this error but no straight answer. Also, most people didn't have this bug all the time, while I always get it. Even on a clean new project.
Any ideas?
I was able to get past this error by changing the way my method signature was written before trying to generate the sequence diagram.
when I was getting the error it was written as such:
ClassName1 IInterfaceName.SubmitData(string username, string password, string data)
I changed it to:
public ClassName1 SubmitData(string username, string password, string data)
and it let me generate the diagram
perhaps this is something to do with interfaces and explicitly stating that the method is public?
HTH!
This topic has information about this issue:
A blank sequence diagram is generated after the following message is displayed:
"Object reference not set to an instance of an object."
This issue occurs when a sequence diagram is generated from an explicit implementation of an interface method, and the diagram is not added to the source project automatically. > An explicit implementation precedes the method name with the interface name
and a period (.).
For example, this issue occurs when you generate a sequence diagram from the following
signature and do not add the sequence diagram to the project automatically:
void ILinkedWorkItemExtension.OnWorkItemCreated() {}
Sequence diagram can not reverse all methods !!
Sometimes the method nature or other instances makes it impossible.

Resources