Error: "string must be exactly one character long"

P

Paolo

I'm getting this error message when running a LINQtoSQL query. My entity
classes are as follows:

[Table(Name="Activities")]
public partial class Activity
{
#region Fields
[Column(IsPrimaryKey = true, DbType="SmallDateTime NOT NULL")]
public DateTime Activity_Date { get; set; }

[Column(IsPrimaryKey = true, DbType = "Char(1) NOT NULL",
CanBeNull=false)]
public char Activity_Type { get; set; }

[Column(DbType="TinyInt NOT NULL")]
public byte Activity_Distance {get; set; }

[Column(DbType = "Char(10) NOT NULL", CanBeNull=false)]
public string Activity_Duration {get; set; }

[Column(DbType = "Char(35) NOT NULL", CanBeNull=false)]
public string Activity_Route {get; set; }
#endregion

private EntityRef<Type> _Type;

[Association(Name = "Type_Activity", Storage = "_Type",
ThisKey = "Activity_Type", OtherKey = "Type_Id",
IsForeignKey = true, DeleteRule = "NO ACTION")]

public Type Type
{
get { return this._Type.Entity; }
set { this._Type.Entity = value; }
}
}

[Table(Name="Types")]
public partial class Type
{
#region Fields
[Column(IsPrimaryKey = true, DbType = "Char(1) NOT NULL", CanBeNull
= false)]
public char Type_Id { get; set; }

[Column(DbType = "Char(8) NOT NULL", CanBeNull = false)]
public char Type_Desc { get; set; }
#endregion

private EntitySet<Activity> _Activities;

[Association(Storage = "_Activities", ThisKey = "Type_Id", OtherKey
= "Activity_Type")]

public EntitySet<Activity> Activities
{
get { return this._Activities; }
set { this._Activities.Assign(value); }

I am joining on Activities.Activity_Type and Types.Type_Id.

I'd appreciate some guidance on how to overcome this error because I can't
see what I may have done incorrectly.

I don't know if it's relevant but my query is as follows:

private static void GetAct_Types(DBDataContext db)
{
var act_types =
from a in db.Activities
from t in db.Types
where a.Activity_Type == t.Type_Id
select new { a.Activity_Date,
a.Activity_Type,
t.Type_Desc,
a.Activity_Distance,
a.Activity_Duration,
a.Activity_Route};

foreach (var row in act_types)
{
Console.WriteLine("{0}\t; {1}\t; {2}\t; {3}\t; {4}",
row.Activity_Date,
row.Type_Desc,
row.Activity_Distance,
row.Activity_Duration,
row.Activity_Route);
}
}


}
}
 
J

Jeroen Mostert

Paolo said:
[Column(DbType = "Char(8) NOT NULL", CanBeNull = false)]
public char Type_Desc { get; set; }

Types don't match. CHAR(8) does not fit in a char.
 
P

Paolo

Jeroen: I'm joining on Activity_Type and Type_Id, both of which are Char(1).

Jeroen Mostert said:
Paolo said:
[Column(DbType = "Char(8) NOT NULL", CanBeNull = false)]
public char Type_Desc { get; set; }

Types don't match. CHAR(8) does not fit in a char.
 
P

Paolo

Jeroen: oops, I see what you're saying. Type_Desc needs to be string.

Thanks

Jeroen Mostert said:
Paolo said:
[Column(DbType = "Char(8) NOT NULL", CanBeNull = false)]
public char Type_Desc { get; set; }

Types don't match. CHAR(8) does not fit in a char.
 
R

RS Emenu

Here a good link that providing good details about maintaing Transaction in LINQ to SQL

<a href="http://www.a2zmenu.com/LINQ/Maintain Transaction in LINQ to SQL.aspx">
I'm getting this error message when running a LINQtoSQL query. My entity
classes are as follows:

[Table(Name="Activities")]
public partial class Activity
{
#region Fields
[Column(IsPrimaryKey = true, DbType="SmallDateTime NOT NULL")]
public DateTime Activity_Date { get; set; }

[Column(IsPrimaryKey = true, DbType = "Char(1) NOT NULL",
CanBeNull=false)]
public char Activity_Type { get; set; }

[Column(DbType="TinyInt NOT NULL")]
public byte Activity_Distance {get; set; }

[Column(DbType = "Char(10) NOT NULL", CanBeNull=false)]
public string Activity_Duration {get; set; }

[Column(DbType = "Char(35) NOT NULL", CanBeNull=false)]
public string Activity_Route {get; set; }
#endregion

private EntityRef<Type> _Type;

[Association(Name = "Type_Activity", Storage = "_Type",
ThisKey = "Activity_Type", OtherKey = "Type_Id",
IsForeignKey = true, DeleteRule = "NO ACTION")]

public Type Type
{
get { return this._Type.Entity; }
set { this._Type.Entity = value; }
}
}

[Table(Name="Types")]
public partial class Type
{
#region Fields
[Column(IsPrimaryKey = true, DbType = "Char(1) NOT NULL", CanBeNull
= false)]
public char Type_Id { get; set; }

[Column(DbType = "Char(8) NOT NULL", CanBeNull = false)]
public char Type_Desc { get; set; }
#endregion

private EntitySet<Activity> _Activities;

[Association(Storage = "_Activities", ThisKey = "Type_Id", OtherKey
= "Activity_Type")]

public EntitySet<Activity> Activities
{
get { return this._Activities; }
set { this._Activities.Assign(value); }

I am joining on Activities.Activity_Type and Types.Type_Id.

I'd appreciate some guidance on how to overcome this error because I can't
see what I may have done incorrectly.

I don't know if it's relevant but my query is as follows:

private static void GetAct_Types(DBDataContext db)
{
var act_types =
from a in db.Activities
from t in db.Types
where a.Activity_Type == t.Type_Id
select new { a.Activity_Date,
a.Activity_Type,
t.Type_Desc,
a.Activity_Distance,
a.Activity_Duration,
a.Activity_Route};

foreach (var row in act_types)
{
Console.WriteLine("{0}\t; {1}\t; {2}\t; {3}\t; {4}",
row.Activity_Date,
row.Type_Desc,
row.Activity_Distance,
row.Activity_Duration,
row.Activity_Route);
}
}


}
}
Types do not match. CHAR(8) does not fit in a char.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top