npoco


Any example of using join in query applyable for npoco


Could you give me any example of querying and mapping result set from joined tables? I have following code:
DTO:
public class FormCatalogRecord
{
[Column("MFormId")]
public int Id { get; set; }
[Column("SGroupId")]
public int? GroupId { get; set; }
[Column("SGroupName")]
public string GroupName { get; set; }
[Column("STypeFormId")]
public int TypeId { get; set; }
[Column("MFormKod")]
public string Code { get; set; }
[Column("MFormName")]
public string Name { get; set; }
[Column("SFormPeriodName")]
public string Period { get; set; }
[Column("MFormDateStart")]
public DateTime? DateStarts { get; set; }
[Column("MFormDateEnd")]
public DateTime? DateEnds { get; set; }
[Column("MFormPublish")]
public DateTime? PublishDate { get; set; }
}
Query:
string formsQueryStr =
"FROM MForm " +
"INNER JOIN SFormPeriod ON MForm.SFormPeriodId = SFormPeriod.SFormPeriodId " +
"INNER JOIN SGroup ON MForm.SGroupId = SGroup.SGroupId " +
"ORDER BY MForm.SGroupId";
var test = db.Fetch<FormCatalogRecord>(formsQueryStr);
The result is exception: "Ambiguous column name 'SGroupId'".
I tried to change attribute:
[Column("MForm.SGroupId")]
public int? GroupId { get; set; }
Now I get an exception
Invalid column name 'MForm.SGroupId'
Surprisingly I didn't found any examples in official documentation. Any help valid for npoco will be useful.
UPDATE
For my first case I'm getting following SQL generated:
SELECT
[MFormId] AS [Id], [SGroupId] AS [GroupId],
[SGroupName] AS [GroupName], [STypeFormId] AS [TypeId],
[MFormKod] AS [Code], [MFormName] AS [Name],
[SFormPeriodName] AS [Period], [MFormDateStart] AS [DateStarts],
[MFormDateEnd] AS [DateEnds], [MFormPublish] AS [PublishDate]
FROM
MForm
INNER JOIN
SFormPeriod ON MForm.SFormPeriodId = SFormPeriod.SFormPeriodId
INNER JOIN
SGroup ON MForm.SGroupId = SGroup.SGroupId
ORDER BY
MForm.SGroupId
I think I need some way to add "MForm." before "[SGroupId] AS [GroupId]". Would be nice if column attribute could support syntax like [Column("TableName.ColumnName")]
NPooc and PetaPoco are different projects now it's hard to relate each with the other these days.
As for your question. Have you tried
string formsQueryStr =
"SELECT MForm.*" +
"FROM MForm " +
"INNER JOIN SFormPeriod ON MForm.SFormPeriodId = SFormPeriod.SFormPeriodId " +
"INNER JOIN SGroup ON MForm.SGroupId = SGroup.SGroupId " +
"ORDER BY MForm.SGroupId";
var test = db.Fetch<FormCatalogRecord>(formsQueryStr);

Related Links

NPoco mapping primarykey error
Nopoc Execute() method returns -1
Creating a new database using NPoco
Creating Custom Ignore attribute only for Update methods?
NPoco One-To-Many and Many-To-Many
Any example of using join in query applyable for npoco
How do I format a query to fetch an aggregate root with just related ids

Categories

HOME
javafx
stata
sip
file-upload
blob
highmaps
sugarcrm
schema
cdn
android-webview
doctrine2
google-app-maker
oms
javascript-debugger
minimum
aggregate
brightway
smooth-scrolling
sonarlint
beaker-notebook
adobe-captivate
typeclass
spock
delphi-2010
concrete5
unity3d-5
oracle-nosql
luhn
border-layout
gstreamer-1.0
lighting
abide
pygraphviz
scalamock
cowboy
java-5
quartz
datagridviewcombobox
amazon-rds-aurora
gridgain
spring-ide
openidm
riemann
fluent-nhibernate-mapping
programming-pearls
liferay-ide
copy-constructor
gevent
alfred
change-password
db2-zos
django-taggit
aws-kms
database-administration
music-player
nslocalizedstring
videoview
clear
dynamics-nav-2013
skscene
biginsights
transport
eula
data-representation
genero
veeam
shunting-yard
uiblureffect
javadb
report-builder2.0
tigase
system.net
powerpoint-2010
drawable
telerik-appbuilder
pyalgotrade
pidgin
slimscroll
node-mongodb-native
code-complete
ironworker
kohana-orm
qgraphicsscene
codeigniter-form-helper
libx264
hypertable
sup
bash4
socketasynceventargs
code-organization
mcpd
execjs
soapexception
funambol
noise-reduction
jquery-attributes
atmega16
file-icons
j++

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App