Hi,
Rocky or anyone else reading this, I have a question. Was the PTracker.dbml and Security.dbml generated utilizing SQLMetal or by hand? I am wondering because I am starting a large project and am diving in head first utilizing LINQ, CSLA 3.5 and all the latest and greatest stuff and I generated my dbml file utilizing SQLMetal. Now, here is what I get with SQLMetal:
public
partial class Usp_csla_SelectProductsAllResultAnd here is what is in Rocky's dbml
public
partial class getRolesResultThe SQLMetal generated code sticks in the System.Nullable<int> stuff and I get an error message like:
Error 1 The best overloaded method match for 'Csla.Core.BusinessBase.LoadProperty<int>(Csla.PropertyInfo<intt>, int)' has some invalid arguments D:\Visual Studio 2008\CSLA Framework\BAS\BAS.Operations.Library\InventoryIndicator.cs 148 7 BAS.Operations.Library
And also
Error 2 Argument '2': cannot convert from 'int?' to 'int' D:\Visual Studio 2008\CSLA Framework\BAS\BAS.Operations.Library\InventoryIndicator.cs 148 57 BAS.Operations.Library
Now, I know why the int? and int error are there is because the SQLMetal generated the Nullable before product Id.
What I am wondering is do I have to go in and fix all this stuff by hand and if I generate SQLMetal again, pick out the stuff that changed and put it in there?
Anyway, let me know if anyone else has had this happen and what you did to fix it!! I guess now, I will go in and hand fix the SQLMetal generated code for things to work.
Thanks in adavance for yor help
Keith
Thanks Rocky, I will try the Designer and see how the 2 compare and then post the forum. Also, something could have changed between the beta of VS2008 and the release as Joseph Rattz pointed out as I discovered a discrepancy in his book versus what was generated. Anyway, I will post on the forum what happens as I am sure someone else will be asking this question in the future.
Keith
Ok,
After a quick comparison, SQLMetal and the VS Designer do produce different results. SQLMetal inserts some additional attributes when it declares variables for user defined sql stored procedures (usp's). For example:
public partial class Usp_csla_SelectPositionProductGroupsAllResult
{
// KSS 04/21/2008
//private System.Nullable<short> _PositionProductGroupId;
private short _PositionProductGroupId;
private string _PositionProductGroupName;
private System.Data.Linq.Binary _LastChanged;
public Usp_csla_SelectPositionProductGroupsAllResult()
{
}
[Column(Storage="_PositionProductGroupId", DbType="SmallInt")]
//public System.Nullable<short> PositionProductGroupId
public short PositionProductGroupId
{
get
{
return this._PositionProductGroupId;
}
set
{
if ((this._PositionProductGroupId != value))
{
this._PositionProductGroupId = value;
}
}
}
[Column(Storage="_PositionProductGroupName", DbType="VarChar(30)")]
public string PositionProductGroupName
{
get
{
return this._PositionProductGroupName;
}
set
{
if ((this._PositionProductGroupName != value))
{
this._PositionProductGroupName = value;
}
}
}
[Column(Storage="_LastChanged", DbType="rowversion")]
public System.Data.Linq.Binary LastChanged
{
get
{
return this._LastChanged;
}
set
{
if ((this._LastChanged != value))
{
this._LastChanged = value;
}
}
}
}
Note the items commented out. I had to do that for the CSLA code to work. That was produced by SQLMetal. I was having a hard time why things were not compiling and I was getting weird messages until I looked closely at the code in PTracker and then went to my designer.cs class. When I commented out the problem lines and replaced them with lines similar to PTracker they worked. I then generated the code with the designer in Visual Studio and it produced correct code. I don't know if this is a bug or if it is supposed to be this way, but I think the 2 items should produce similar code so I consider it a bug. I mean, what good is a tool that generates code and then you have to go in and change/fix a lot of it for things to work. And then if you regen it again, you loose all your changes. Not good in my opinion.
Also, I have a table named tlkpNoYes and SQLMetal and the designer gen it to be tlkpNoYe, but SQLMetal makes the t an uppercase T so it is TlkpNoYe. I guess it does that to be gramatically correct, however, I don't care about gramatically correct code! If something ends with s, just add es on the end so it is tlkpNoYeses.
Anyway, just thought I would let everyone know what I have found so far and I have only scratched the surface. I will have to mail Joseph Rattz and let him know what I found out also as I have been delving into his LINQ book and found it excellent. If you need a book on LINQ, buy it, don't even think about it, just buy it!
Keith
Good feedback. BTW, I believe, SQLMetal has command line
option not to “un-pluralize” table names.
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: CyclingFoodmanPA
[mailto:cslanet@lhotka.net]
Sent: Tuesday, April 22, 2008 10:40 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] SQLMetal, PTracker.dbml and Security.dbml
Ok,
After a quick comparison, SQLMetal and the VS Designer do produce different
results. SQLMetal inserts some additional attributes when it declares
variables for user defined sql stored procedures (usp's). For example:
public partial class Usp_csla_SelectPositionProductGroupsAllResult
{
// KSS 04/21/2008
//private System.Nullable<short> _PositionProductGroupId;
private short _PositionProductGroupId;
private string _PositionProductGroupName;
private System.Data.Linq.Binary _LastChanged;
public Usp_csla_SelectPositionProductGroupsAllResult()
{
}
[Column(Storage="_PositionProductGroupId",
DbType="SmallInt")]
//public System.Nullable<short> PositionProductGroupId
public short PositionProductGroupId
{
get
{
return this._PositionProductGroupId;
}
set
{
if ((this._PositionProductGroupId != value))
{
this._PositionProductGroupId = value;
}
}
}
[Column(Storage="_PositionProductGroupName",
DbType="VarChar(30)")]
public string PositionProductGroupName
{
get
{
return this._PositionProductGroupName;
}
set
{
if ((this._PositionProductGroupName != value))
{
this._PositionProductGroupName = value;
}
}
}
[Column(Storage="_LastChanged",
DbType="rowversion")]
public System.Data.Linq.Binary LastChanged
{
get
{
return this._LastChanged;
}
set
{
if ((this._LastChanged != value))
{
this._LastChanged = value;
}
}
}
}
Note the items commented out. I had to do that for the CSLA code to
work. That was produced by SQLMetal. I was having a hard time why
things were not compiling and I was getting weird messages until I looked
closely at the code in PTracker and then went to my designer.cs class.
When I commented out the problem lines and replaced them with lines similar to
PTracker they worked. I then generated the code with the designer in
Visual Studio and it produced correct code. I don't know if this is a bug
or if it is supposed to be this way, but I think the 2 items should produce
similar code so I consider it a bug. I mean, what good is a tool that
generates code and then you have to go in and change/fix a lot of it for things
to work. And then if you regen it again, you loose all your
changes. Not good in my opinion.
Also, I have a table named tlkpNoYes and SQLMetal and the designer gen it to
be tlkpNoYe, but SQLMetal makes the t an uppercase T so it is TlkpNoYe. I
guess it does that to be gramatically correct, however, I don't care about
gramatically correct code! If something ends with s, just add es on the
end so it is tlkpNoYeses.
Anyway, just thought I would let everyone know what I have found so far and
I have only scratched the surface. I will have to mail Joseph Rattz and
let him know what I found out also as I have been delving into his LINQ book
and found it excellent. If you need a book on LINQ, buy it, don't even
think about it, just buy it!
Keith
Copyright (c) Marimer LLC