Drop down shows each record several times - c#

i am picking list of names from database, according to scenario each name exists many times in database, That's ok. Now i have filled a DROPDOWNLIST with those names but in drop down list each name appears several times:
but i want to display each name 1 time in DROPDOWN. I have used distict() but not working.
USING MVC 3, Linq to SQL
Controller:
namespace EmployeeAttendance_app.Controllers
{
public class HomeController : Controller
{
EmployeeAtdDataContext DataContext = new EmployeeAtdDataContext();
public ActionResult Index()
{
ViewBag.Message = "Precise Technology Consultants";
//var EmployeeAtd = DataContext.GetAttendance_Sp();
IEnumerable<GetAtdRecord_SpResult> EmployeeAtd = DataContext.GetAtdRecord_Sp(null).ToList();
var names = (from n in DataContext.EmployeeAtds select n).Distinct();
//ViewData["EmplID"] = new SelectList(names, "EmplID", "EmplName");
return View(EmployeeAtd);
}
public ActionResult ddl()
{
var names = (from n in DataContext.EmployeeAtds select n).Distinct();
ViewData["EmplID"] = new SelectList(names, "EmplID", "EmplName");
return View();
}
public ActionResult showDDL(string EmplID)
{
ViewBag.EmplID = EmplID;
return View();
}
public ActionResult About()
{
return View();
}
Views:
#{
ViewBag.Title = "ddl";
}
<h2>ddl</h2>
#using (Html.BeginForm("showDDL", "Home", FormMethod.Get))
{
<fieldset>
Employers
#Html.DropDownList("EmplID", "Select Name")
<p>
<input type="submit" value="Submit" />
</p>
</fieldset>
}
ModeL
amespace EmployeeAttendance_app.Models
{
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="a1")]
public partial class EmployeeAtdDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
#endregion
public EmployeeAtdDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["a1ConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public EmployeeAtdDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public EmployeeAtdDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public EmployeeAtdDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public EmployeeAtdDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<EmployeeAtd> EmployeeAtds
{
get
{
return this.GetTable<EmployeeAtd>();
}
}
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.GetAtdRecord_Sp")]
public ISingleResult<GetAtdRecord_SpResult> GetAtdRecord_Sp([global::System.Data.Linq.Mapping.ParameterAttribute(Name="EmplID", DbType="Int")] System.Nullable<int> emplID)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), emplID);
return ((ISingleResult<GetAtdRecord_SpResult>)(result.ReturnValue));
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.V_EmployeeAtd")]
public partial class EmployeeAtd
{
private string _EmplID;
private string _EmplName;
private string _RecDate;
private string _RecTime;
private string _DeptName;
public EmployeeAtd()
{
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EmplID", DbType="Char(8) NOT NULL", CanBeNull=false)]
public string EmplID
{
get
{
return this._EmplID;
}
set
{
if ((this._EmplID != value))
{
this._EmplID = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EmplName", DbType="NVarChar(40) NOT NULL", CanBeNull=false)]
public string EmplName
{
get
{
return this._EmplName;
}
set
{
if ((this._EmplName != value))
{
this._EmplName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_RecDate", DbType="Char(10)")]
public string RecDate
{
get
{
return this._RecDate;
}
set
{
if ((this._RecDate != value))
{
this._RecDate = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_RecTime", DbType="Char(5)")]
public string RecTime
{
get
{
return this._RecTime;
}
set
{
if ((this._RecTime != value))
{
this._RecTime = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DeptName", DbType="NVarChar(50)")]
public string DeptName
{
get
{
return this._DeptName;
}
set
{
if ((this._DeptName != value))
{
this._DeptName = value;
}
}
}
}
public partial class GetAtdRecord_SpResult
{
private string _EmplID;
private string _EmplName;
private string _InTime;
private string _OutTime;
private string _DateVisited;
private string _TimeWorked;
private string _OverTime;
public GetAtdRecord_SpResult()
{
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EmplID", DbType="Char(8) NOT NULL", CanBeNull=false)]
public string EmplID
{
get
{
return this._EmplID;
}
set
{
if ((this._EmplID != value))
{
this._EmplID = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_EmplName", DbType="NVarChar(40) NOT NULL", CanBeNull=false)]
public string EmplName
{
get
{
return this._EmplName;
}
set
{
if ((this._EmplName != value))
{
this._EmplName = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_InTime", DbType="Char(5)")]
public string InTime
{
get
{
return this._InTime;
}
set
{
if ((this._InTime != value))
{
this._InTime = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OutTime", DbType="Char(5)")]
public string OutTime
{
get
{
return this._OutTime;
}
set
{
if ((this._OutTime != value))
{
this._OutTime = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DateVisited", DbType="Char(10) NOT NULL", CanBeNull=false)]
public string DateVisited
{
get
{
return this._DateVisited;
}
set
{
if ((this._DateVisited != value))
{
this._DateVisited = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TimeWorked", DbType="Char(5)")]
public string TimeWorked
{
get
{
return this._TimeWorked;
}
set
{
if ((this._TimeWorked != value))
{
this._TimeWorked = value;
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OverTime", DbType="VarChar(6)")]
public string OverTime
{
get
{
return this._OverTime;
}
set
{
if ((this._OverTime != value))
{
this._OverTime = value;
}
}
}
}
}
pragma warning restore 1591

I think you are implementing distinct on n which contains all properties of class. You need to apply distinct on required columns only. Like
var empList= DataContext.EmployeeAtds.Select(n => new
{
EmplID= n.EmplID,
EmplName= n.EmplName
}).Distinct().ToList();
OR
var empList= (from n in DataContext.EmployeeAtds select new{ EmplID= n.EmplID,
EmplName= n.EmplName}).Distinct();

You need to make sure that your underlying object overrides GetHashCode and Equals in order for it to work properly.
Please see here for more information:
http://msdn.microsoft.com/en-us/library/ms173147(v=vs.80).aspx
As an example, if you have an object called EmployeeAtd it needs to implement the above two methods in order to know when comparative objects are equal.
This is a simple example but you may consider an EmployeeAtd objects the same if they have matching EmplID's, an example Equals override could be:
public override bool Equals(object obj)
{
if (obj == null) return false;
if (this.GetType() != obj.GetType()) return false;
EmployeeAtd emp = (EmployeeAtd) obj;
if (!Object.Equals(EmplID, emp.EmplID)) return false;
return true;
}
If your EmplID is an int you could simply implement the GetHashCode as follows:
public override int GetHashCode ()
{
return EmplID.GetHashCode();
}
This is no way best practice but there are plenty of other questions on how to do this.
What is the best way to implement this composite GetHashCode()
Why is it important to override GetHashCode when Equals method is overridden?

You can use DISTINCT safely, I am not sure where exactly you are facing problem. Please follow this example. Say I Have a database table this way -
Then I write following Stored Procedure
USE [Sample]
GO
CREATE PROCEDURE GiveNames
AS
SELECT DISTINCT(Name) FROM [dbo].[SampleTable]
GO
Then I create a MVC Project and add EDMX and used the content in Controller in following way -
public class EdmxController : Controller
{
//
// GET: /Edmx/
public ActionResult Index()
{
DDLModel model = new DDLModel();
model.Items = new List<string>();
using (var entities = new SampleEntities1())
{
model.Items = entities.GiveNames().ToList();
}
return View(model);
}
}
public class DDLModel
{
public List<String> Items { get; set; }
}
My View -
#model MVC.Controllers.DDLModel
#{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<div>
#Html.DropDownList("MyDDL",new SelectList(Model.Items), "--Choose any Item--")
</div>
And my output doesn't conduct any duplicates -

Related

Nopcommerce unable to find my Payment Method plugin's component

I am developing a customized Payment Method plugin for my client. I am a beginner in Nopcommerce plugin development and here's my plugin directory structure:
Code
Here's my CODBookingPaymentProcessor.cs
public class CODBookingPaymentProcessor : BasePlugin, IPaymentMethod
{
#region Ctor
public CODBookingPaymentProcessor()
{
}
#endregion
#region Methods
public bool SupportCapture => false;
public bool SupportPartiallyRefund => false;
public bool SupportRefund => false;
public bool SupportVoid => false;
public RecurringPaymentType RecurringPaymentType => RecurringPaymentType.NotSupported;
public PaymentMethodType PaymentMethodType => PaymentMethodType.Standard;
public bool SkipPaymentInfo => false;
public string PaymentMethodDescription => "Pay booking and extras before order placing.";
public CancelRecurringPaymentResult CancelRecurringPayment(CancelRecurringPaymentRequest cancelPaymentRequest)
{
return new CancelRecurringPaymentResult();
}
public bool CanRePostProcessPayment(Order order)
{
if (order == null)
throw new ArgumentNullException(nameof(order));
//it's not a redirection payment method. So we always return false
return false;
}
public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
{
return new CapturePaymentResult { Errors = new[] { "Capture method not supported" } };
}
public decimal GetAdditionalHandlingFee(IList<ShoppingCartItem> cart)
{
return 0;
}
public ProcessPaymentRequest GetPaymentInfo(IFormCollection form)
{
return new ProcessPaymentRequest();
}
public string GetPublicViewComponentName()
{
return "CODBooking";
}
public bool HidePaymentMethod(IList<ShoppingCartItem> cart)
{
return false;
}
public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
{
}
public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
{
return new ProcessPaymentResult();
}
public ProcessPaymentResult ProcessRecurringPayment(ProcessPaymentRequest processPaymentRequest)
{
return new ProcessPaymentResult();
}
public RefundPaymentResult Refund(RefundPaymentRequest refundPaymentRequest)
{
return new RefundPaymentResult();
}
public IList<string> ValidatePaymentForm(IFormCollection form)
{
return null;
}
public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
{
return new VoidPaymentResult();
}
#endregion
}
PaymentCODBookingController.cs code:
[AuthorizeAdmin]
[Area(AreaNames.Admin)]
public class PaymentCODBookingController : BasePaymentController
{
private readonly IPermissionService _permissionService;
public PaymentCODBookingController(IPermissionService permissionService)
{
_permissionService = permissionService;
}
}
CODBookingViewComponent.cs code:
[ViewComponent(Name = "CODBooking")]
public class CODBookingViewComponent : NopViewComponent
{
public IViewComponentResult Invoke()
{
return View("~/Plugins/Payments.CODBookingPaymentProcessor/Views/CODBooking.cshtml");
}
}
CODBooking.cshtml code:
#{
Layout = "";
}
<p>TESTING...</p>
Issue
The problem is that system is unable to find CODBooking.cshtml view. I tried every possible path format but none worked.
I checked other plugins and they are also defining the component path just like mine.
There is a typo in the .cshtml filename "Boooking.cshtml" :) Look closely.

Make my Type work like a list

I have created a list of my own type... (Classes for custom types at bottom of page)
List<gridRecord> lgr = new List<gridRecord>();
lgr = populatedList();
I validate each field in the List with the code bellow... (This works fine!)
foreach (gridRecord gr in lgr)
{
gr.Quantity.validate();
gr.Title.validate();
gr.Pages.validate();
dt.Rows.Add(gr.Title.Value.ToString(), gr.Quantity.Value.ToString(), gr.Pages.Value.ToString());
}
However I will be adding new gridFields to the gridRecord Class, and do not want to change the code that is validating.
so...I would like to be able to do something like this...
foreach (gridField gf in lgr)
{
gf.Validate();
}
grid Record Class...
class gridRecord : Validateit
{
//Constructor
public gridRecord()
{
Quantity = new quantityField();
Title = new titleField();
Pages = new pagesField();
}
private quantityField quantity;
private titleField title;
private pagesField pages;
public quantityField Quantity
{
get { return quantity; }
set { quantity = value; }
}
public titleField Title
{
get { return title; }
set { title = value; }
}
public pagesField Pages
{
get { return pages; }
set { pages = value; }
}
public override void Validate()
{
}
}
gridField Class...
class gridField : Validateit
{
public gridField()
{
Value = "---";
isValid = false;
message = "";
}
private string value;
protected bool isValid;
private string message;
public string Value
{
get { return this.value; }
set { this.value = value; }
}
public bool IsValid
{
get { return isValid; }
set { isValid = value; }
}
public string Message
{
get { return message; }
set { message = value; }
}
public override void Validate()
{
}
}
do I need to use IEnumerable if so how?
Thanks
If you want code like this:
foreach (gridRecord gr in lgr)
{
gr.Validate();
}
It is a simple case of implementing what you need within that Validate method of gridRecord (BTW: That class should be named GridRecord - classes should start with an upper case character according to C# naming convention)
class gridRecord : Validateit
{
//.. snip
public override void Validate()
{
this.Quantity.Validate();
this.Title.Validate();
this.Pages.Validate();
}
}
If, however, you want to enumerate all the fields you can make each gridRecord implement IEnumerable<gridField> like this:
class gridRecord : Validateit, IEnumerable<gridField>
{
//.. snip
public IEnumerator<gridField> GetEnumerator()
{
yield return Quantity;
yield return Title;
yield return Pages;
}
public IEnumerator GetEnumerator()
{
return GetEnumerator(); // generic version
}
}
Then you can have code like this:
foreach (gridRecord gr in lgr) // enumerate each record
{
foreach(gridField gf in gr) // enumerate each field within each record
{
gf.Validate();
}
}

LinQ Count based on element in child class

I have a JSON class which I used to deserialize my object to :-
public class Response
{
private Meta _meta;
private Result _result;
private Output _output;
public Meta meta
{
set
{
if (this._meta == null)
{
this._meta = new Meta();
}
this._meta = value;
}
get
{
return this._meta;
}
}
public Output output
{
set
{
if (this._output == null)
{
this._output = new Output();
}
this._output = value;
}
get
{
return this._output;
}
}
}
Which inherit
public class Output
{
...
public Verified verified{
get
{
return this._verified;
}
set
{
if (this._verified == null)
{
this._verified = new Verified();
}
this._verified = value;
}
}
in which has sub class of
public class Verified
{
...
public Address Address
{
set
{
if (this.address == null)
{
this.address = new Address();
}
this.address = value;
}
get
{
return this.address;
}
}
public Age Age
{
get
{
return this.age;
}
set
{
if (this.age == null)
{
this.age = new Age();
}
this.age = value;
}
}
public City City
{
get
{
return this.city;
}
set
{
if (this.city == null)
{
this.city = new City();
}
this.city = value;
}
}
...
All the attribute in City, Age, and Address are the same such as
public class Address
{
public int code { get; set; }
public string text { get; set; }
}
I have manage to count how many attribute in the Verified by using
TotalQuestion = response.output.verified.GetType().GetProperties()
.Where(p => !p.PropertyType.IsGenericType
&& !p.PropertyType.IsArray)
.Count();
, and that is only half of my concern. I have to also count now many of the attribute "code" in each of the class in Address, City, Age which has value as 3.
I did tried to add .GetType().GetProperty("code") at the back of the same LinQ I used to query the total amount of question inside, but I got lost in mind how to complete it.
I hope that anyone would be able to advice on possible LinQ solution (hopefully one-liner) type.
Thanks.
Simon
I think this is what you are looking for -
var result = resp.output.verified.GetType().GetProperties().Where(
child => {
var prop = child.GetValue(resp.output.verified, null);
return (int)prop.GetType().GetProperty("code").GetValue(prop, null) == 3;
}).ToList();

Custom Collection/List To Store Custom Objects

I have a customer object class:
public class customerObject
{
private string _address1;
private string _address2;
private string _address3;
private string _category;
private string _country;
private string _county;
private string _custcode;
private string _fullname;
private string _int_rep_hou;
private string _int_rep_key;
private double _lat;
private double _lng;
private string _postcode;
private string _rep_code;
private string _telephone;
public customerObject()
{
}
public string Address1
{
get { return _address1; }
set { _address1 = value; }
}
public string Address2
{
get
{
return _address2;
}
set { _address2 = value; }
}
public string Address3 { get { return _address3; } set { _address3 = value; } }
public string Category
{
get { return _category; }
set { _category = value; }
}
public string Country { get { return _country; } set { _country = value; } }
public string County { get { return _county; } set { _county = value; } }
public string Custcode
{
get { return _custcode; }
set { _custcode = value; }
}
public string Fullname
{
get { return _fullname; }
set { _fullname = value; }
}
public string Int_rep_hou
{
get { return _int_rep_hou; }
set { _int_rep_hou = value; }
}
public string Int_rep_key
{
get { return _int_rep_key; }
set { _int_rep_key = value; }
}
public double Lat { get { return _lat; } set { _lat = value; } }
public double Lng { get { return _lng; } set { _lng = value; } }
public string Postcode { get { return _postcode; } set { _postcode = value; } }
public string Rep_code
{
get { return _rep_code; }
set { Rep_code = value; }
}
public string Telephone { get { return _telephone; } set { _telephone = value; }
}
}
I have a CustomCollections class
public class CustomerCollection
{
public List<customerObject> Customers { get; set; }
}
My method that loops through dt rows and converts to a customer object
public List<Valueobjects.CustomerCollection> dolist(DataTable temptablename)
{
//Create Collection Object
Valueobjects.CustomerCollection Collection = new Valueobjects.CustomerCollection();
foreach (DataRow row in temptablename.Rows)
{
//Create Customer Object
Valueobjects.customerObject Customer = new Valueobjects.customerObject();
//set values of customer object
Customer.Rep_code = "";
Customer.Int_rep_key = "";
Customer.Int_rep_hou = "";
Customer.Fullname = row["Fullname"].ToString().Trim();
Customer.Custcode = row["Custcode"].ToString().Trim();
Customer.Category = row["Category"].ToString().Trim();
Customer.Address1 = row["Address1"].ToString().Trim();
Customer.Address2 = row["Address2"].ToString().Trim();
Customer.Address3 = row["Address3"].ToString().Trim();
Customer.Postcode = row["Postcode"].ToString().Trim();
Customer.Country = row["Country"].ToString().Trim();
Customer.Telephone = row["Telephone"].ToString().Trim();
Customer.Lat = Convert.ToDouble(row["Lat"]);
Customer.Lng = Convert.ToDouble(row["Lng"]);
Customer.County = row["County"].ToString().Trim();
//add to the collection (list)
Collection.Customers.Add(Customer);
}
temptablename = null;
return Collection;
}
However when I create a new Customer object and a new CustomerCollection object I am getting an error when adding the customer to the collection list.
Error:
Error 32 Cannot implicitly convert type
'Classes.Valueobjects.CustomerCollection' to
'System.Collections.Generic.List'
Your method is returning a List<CustomerCollection>:
public List<Valueobjects.CustomerCollection> dolist(DataTable temptablename)
{
//...
}
But the code is trying to return a CustomerCollection:
return Collection;
Just as the error says, these two types are different.
If a CustomerCollection is already a collection of customers, then semantically what is a List<Valueobjects.CustomerCollection>? A collection of collections? It seems like you're over-pluralizing your objects :)
There are two approaches here. Either return a CustomerCollection from the method:
public CustomerCollection dolist(DataTable temptablename)
{
//...
}
Or use a List<Customer> if you want to use generic lists as your collection containers:
public List<Customer> dolist(DataTable temptablename)
{
//...
var Collection = new List<Customer>();
//...
Collection.Add(Customer);
//...
return Collection;
}
Side note: You may want to stick to C# conventions for variable naming. As you can see from the code highlighting here on Stack Overflow, your variable names can easily be mistaken for classes/types, which can cause confusion when supporting the code.
Return a CustomerCollection instead of a List<Valueobjects.CustomerCollection>:
public Valueobjects.CustomerCollection Dolist(DataTable temptablename)
{
// ...
Your object has a list, it is not a list.
MSDN: Inheritance

ObjectDataSource connection

I'm trying to work through Pluralsights ASP.NET Webforms (c#) demos and cannot figure out why my class in my app_code folder will not show in my ObjectDataSource dropdown list when trying to create a new Datasource connection. I've been stuck on this for nearly a week and a half and am new to programming so don't understand all of the lingo after searching for helpful documents. I don't know where to implement what.
Here's the code for my BAL.cs class located in my App_Code Folder and I have a Data folder with a Linq to class connection named Northwind.
// Here is my code for BAL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using Northwind;
public class BAL
{
public List<String> GetCountries()
{
using (var context = new NorthwindDataContext())
{
return (from c in context.Customers
select c.Country).Distinct().ToList();
}
}
public List<Customer> GetCustomersByCountry(string country)
{
using (var context = new NorthwindDataContext())
{
return (from c in context.Customers
where c.Country == country
select c).ToList();
}
}
public Customer GetCustomer(string custID)
{
using (var context = new NorthwindDataContext())
{
return (from c in context.Customers
where c.CustomerID == custID
select c).SingleOrDefault();
}
}
}
}
Now the designer.cs for my Northwind.dbml file
#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.17929
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Northwind
{
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="Northwind")]
public partial class NorthwindDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new
AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
partial void InsertCustomer(Customer instance);
partial void UpdateCustomer(Customer instance);
partial void DeleteCustomer(Customer instance);
#endregion
public NorthwindDataContext() :
base
(global::System.Configuration.ConfigurationManager.ConnectionStrings
["NorthwindConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(string connection,
System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public NorthwindDataContext(System.Data.IDbConnection connection,
System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<Customer> Customers
{
get
{
return this.GetTable<Customer>();
}
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Customers")]
public partial class Customer : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new
PropertyChangingEventArgs(String.Empty);
private string _CustomerID;
private string _CompanyName;
private string _ContactName;
private string _ContactTitle;
private string _Address;
private string _City;
private string _Region;
private string _PostalCode;
private string _Country;
private string _Phone;
private string _Fax;
private string _Image;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnCustomerIDChanging(string value);
partial void OnCustomerIDChanged();
partial void OnCompanyNameChanging(string value);
partial void OnCompanyNameChanged();
partial void OnContactNameChanging(string value);
partial void OnContactNameChanged();
partial void OnContactTitleChanging(string value);
partial void OnContactTitleChanged();
partial void OnAddressChanging(string value);
partial void OnAddressChanged();
partial void OnCityChanging(string value);
partial void OnCityChanged();
partial void OnRegionChanging(string value);
partial void OnRegionChanged();
partial void OnPostalCodeChanging(string value);
partial void OnPostalCodeChanged();
partial void OnCountryChanging(string value);
partial void OnCountryChanged();
partial void OnPhoneChanging(string value);
partial void OnPhoneChanged();
partial void OnFaxChanging(string value);
partial void OnFaxChanged();
partial void OnImageChanging(string value);
partial void OnImageChanged();
#endregion
public Customer()
{
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CustomerID",
DbType="NChar(5) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
public string CustomerID
{
get
{
return this._CustomerID;
}
set
{
if ((this._CustomerID != value))
{
this.OnCustomerIDChanging(value);
this.SendPropertyChanging();
this._CustomerID = value;
this.SendPropertyChanged("CustomerID");
this.OnCustomerIDChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_CompanyName",
DbType="NVarChar(40) NOT NULL", CanBeNull=false)]
public string CompanyName
{
get
{
return this._CompanyName;
}
set
{
if ((this._CompanyName != value))
{
this.OnCompanyNameChanging(value);
this.SendPropertyChanging();
this._CompanyName = value;
this.SendPropertyChanged("CompanyName");
this.OnCompanyNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ContactName",
DbType="NVarChar(30)")]
public string ContactName
{
get
{
return this._ContactName;
}
set
{
if ((this._ContactName != value))
{
this.OnContactNameChanging(value);
this.SendPropertyChanging();
this._ContactName = value;
this.SendPropertyChanged("ContactName");
this.OnContactNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ContactTitle",
DbType="NVarChar(30)")]
public string ContactTitle
{
get
{
return this._ContactTitle;
}
set
{
if ((this._ContactTitle != value))
{
this.OnContactTitleChanging(value);
this.SendPropertyChanging();
this._ContactTitle = value;
this.SendPropertyChanged("ContactTitle");
this.OnContactTitleChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Address",
DbType="NVarChar(60)")]
public string Address
{
get
{
return this._Address;
}
set
{
if ((this._Address != value))
{
this.OnAddressChanging(value);
this.SendPropertyChanging();
this._Address = value;
this.SendPropertyChanged("Address");
this.OnAddressChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_City",
DbType="NVarChar(15)")]
public string City
{
get
{
return this._City;
}
set
{
if ((this._City != value))
{
this.OnCityChanging(value);
this.SendPropertyChanging();
this._City = value;
this.SendPropertyChanged("City");
this.OnCityChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Region",
DbType="NVarChar(15)")]
public string Region
{
get
{
return this._Region;
}
set
{
if ((this._Region != value))
{
this.OnRegionChanging(value);
this.SendPropertyChanging();
this._Region = value;
this.SendPropertyChanged("Region");
this.OnRegionChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_PostalCode",
DbType="NVarChar(10)")]
public string PostalCode
{
get
{
return this._PostalCode;
}
set
{
if ((this._PostalCode != value))
{
this.OnPostalCodeChanging(value);
this.SendPropertyChanging();
this._PostalCode = value;
this.SendPropertyChanged("PostalCode");
this.OnPostalCodeChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Country",
DbType="NVarChar(15)")]
public string Country
{
get
{
return this._Country;
}
set
{
if ((this._Country != value))
{
this.OnCountryChanging(value);
this.SendPropertyChanging();
this._Country = value;
this.SendPropertyChanged("Country");
this.OnCountryChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Phone",
DbType="NVarChar(24)")]
public string Phone
{
get
{
return this._Phone;
}
set
{
if ((this._Phone != value))
{
this.OnPhoneChanging(value);
this.SendPropertyChanging();
this._Phone = value;
this.SendPropertyChanged("Phone");
this.OnPhoneChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Fax",
DbType="NVarChar(24)")]
public string Fax
{
get
{
return this._Fax;
}
set
{
if ((this._Fax != value))
{
this.OnFaxChanging(value);
this.SendPropertyChanging();
this._Fax = value;
this.SendPropertyChanged("Fax");
this.OnFaxChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Image",
DbType="NVarChar(50)")]
public string Image
{
get
{
return this._Image;
}
set
{
if ((this._Image != value))
{
this.OnImageChanging(value);
this.SendPropertyChanging();
this._Image = value;
this.SendPropertyChanged("Image");
this.OnImageChanged();
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new
PropertyChangedEventArgs (propertyName));
}
}
}
}
#pragma warning restore 1591
If they're not showing up in the GUI, try manually specifying which methods go with which actions.
Eg:
[DataObjectMethod(DataObjectMethodType.Select, true)]
[DataObjectMethod(DataObjectMethodType.Insert, true)]
[DataObjectMethod(DataObjectMethodType.Update, true)]
[DataObjectMethod(DataObjectMethodType.Delete, true)]
More info here.
You need to make sure your project type is a Web project, otherwise Visual Studio will not consider the App_Code folder
Make sure you include System.Data.Linq as a reference in your Web.Config file bz adding the following
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
Following is the Web.Config file content. I got the content from the exercise files on the Introduction to ASP.NET 4 WebForms course from pluralsight:
See comments here: stackoverflow.com/questions/16170156/
I think adding an assembly ref to web.config solved the problem for me.

Categories