I've been trying to get a WCF service to access a file database that is stored on a local file system to no avail currently.
I created a database called data.mdf in visual studio 2010 and ran this sql query on it.
create table Person
(PersonID int identity (1000,1) not null,
Name nvarchar(50) not null,
Address nvarchar(max)
create table ImportantPerson
(ImportantPersonID int indentity(1000,1) not null,
Name nvarchar(50) not null,
Address nvarchar(max)
and it successfully created the tables I wanted so I proceeded to create my DataContract:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
namespace MyDataContract
{
public class DataDB: DataContext
{
public Table<Person> Persons;
public Table<Important> Importants;
public DataDB(string connstr)
: base(connstr)
{
}
}
[DataContract]
[Table(Name = "Person")]
public class Person
{
private int _ID;
private String _Name;
private String _Address
public Person()
{
}
public Person(String Name, String Address)
{
_Name = Name;
_Address = Address;
}
[DataMember]
[Column(IsPrimaryKey = true, Storage = "PersonID", DbType="int not null", IsDbGenerated = true)]
public int PersonIdentification
{
get{ return _PersonID;}
set{ _PersonID = value;}
}
[DataMember]
[Column(Storage = "Name")]
{
get{ return _Name;}
set{ _Name = value;}
}
[DataMember]
[Column(Storage = "Address")]
{
get{ return _Address;}
set{_Address= value;}
}
public class Person
{
private int _ID;
private String _Name;
private String _Address
public ImportantPerson()
{
}
public ImportantPerson(String Name, String Address)
{
_Name = Name;
_Address = Address;
}
[DataMember]
[Column(IsPrimaryKey = true, Storage = "ImportantPersonID", DbType="int not null", IsDbGenerated = true)]
public int PersonIdentification
{
get{ return _PersonID;}
set{ _PersonID = value;}
}
[DataMember]
[Column(Storage = "Name")]
{
get{ return _Name;}
set{ _Name = value;}
}
[DataMember]
[Column(Storage = "Address")]
{
get{ return _Address;}
set{_Address= value;}
}
When I try to instantiate a connection to the database
MyDataContract.DataDB data = new MyDataContract.DataDB(@"c:\data\data.mdf");
I get an exception
Bad Storage property: 'PersonID' on member 'MyDataContract.Person.PersonIdentification'.
Can someone help me figure out what's wrong? From everything I've read this should work although I could miss something.