Auparavant, je jouais avec Silverlight et RIA, j'utilisais un modèle de données d'entité ADO.NET et le contexte de domaine. J'enseigne moi-même comment exécuter une procédure stockée à partir de RIA, et je n'ai pas réussi à l'utiliser avec la configuration précédente. J'ai alors commencé à essayer en utilisant la méthode LINQ to SQL. Je l'ai fait ce qui suit:Linq to SQL vs entité Data Model: Obtention d'un proc stocké pour exécuter
- Ajouté le DBML
- glisser baissai table et exemple stockée proc
- enregistré le DBML et construit et reconstruit la solution et les fichiers de projet.
- Créez un service de domaine et tentez d'ajouter le dbml.
Voici mon DBML
Voici mon erreur. La liste des classes DataContext/ObjectContext disponibles s'affiche vide. J'ai reconstruit de nombreuses fois et même redémarré le studio visuel.
Alors voici mes questions:
- Est-il un moyen facile de faire une procédure stockée avec ADO.Net que je manquais je pouvais therfore ignorer l'ajout d'une classe LinqToSql. Je manque quelque chose de vraiment simple pour ajouter la classe dbml et ajouter un proc stocké de cette façon.
CODE
ZipCodeDataClasses.dbml.layout
<?xml version="1.0" encoding="utf-8"?>
<ordesignerObjectsDiagram dslVersion="1.0.0.0" absoluteBounds="0, 0, 11, 8.5" name="ZipCodeDataClasses">
<DataContextMoniker Name="/ZipCodeDataClassesDataContext" />
<nestedChildShapes>
<classShape Id="de7acfae-754b-4577-b227-3a33198fdc95" absoluteBounds="7.125, 2.375, 2, 1.3862939453125">
<DataClassMoniker Name="/ZipCodeDataClassesDataContext/ZipCode" />
<nestedChildShapes>
<elementListCompartment Id="8744ad5e-7b77-4770-911d-6dc963876e40" absoluteBounds="7.14, 2.835, 1.9700000000000002, 0.8262939453125" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />
</nestedChildShapes>
</classShape>
</nestedChildShapes>
</ordesignerObjectsDiagram>
ZipCodeDataClasses.designer.cs
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace StoredProcedureTest.Web
{
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="ZIPCODES")]
public partial class ZipCodeDataClassesDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
#endregion
public ZipCodeDataClassesDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["ZIPCODESConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public ZipCodeDataClassesDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public ZipCodeDataClassesDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public ZipCodeDataClassesDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public ZipCodeDataClassesDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<ZipCode> ZipCodes
{
get
{
return this.GetTable<ZipCode>();
}
}
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.sp_GetCityByZip")]
public int sp_GetCityByZip([global::System.Data.Linq.Mapping.ParameterAttribute(Name="ZIP", DbType="NVarChar(10)")] string zIP, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Return", DbType="NVarChar(26)")] ref string @return)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), zIP, @return);
@return = ((string)(result.GetParameterValue(1)));
return ((int)(result.ReturnValue));
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.ZipCodes")]
public partial class ZipCode
{
private string _City;
private string _State;
private int _Zip;
public ZipCode()
{
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_City", DbType="VarChar(25)")]
public string City
{
get
{
return this._City;
}
set
{
if ((this._City != value))
{
this._City = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_State", DbType="VarChar(2)")]
public string State
{
get
{
return this._State;
}
set
{
if ((this._State != value))
{
this._State = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Zip", DbType="Int NOT NULL")]
public int Zip
{
get
{
return this._Zip;
}
set
{
if ((this._Zip != value))
{
this._Zip = value;
}
}
}
}
}
#pragma warning restore 1591
Merci pour le lien. Prouvé utile. J'ai trouvé une vidéo qui m'a aidé à comprendre ce qui se passait un peu mieux, j'espère que cela vous aidera aussi. http://msdn.microsoft.com/en-us/vcsharp/dd565862.aspx –
Merci pour le lien. La vidéo a l'air bien, je vais devoir essayer la mise en œuvre et voir si je peux le faire fonctionner. – Stryder