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
asterisk
joomla
logging
http
macros
teradata
cors
packet
wifi
webvr
gap-system
spss
x509certificate
symfony-sonata
grid
terminal
yuv
vsixmanifest
cracking
angularjs-ng-repeat
mbed
exchange-transport-agents
dat.gui
luis
facebook-marketing-api
ofbiz
novacode-docx
aiml
sonarlint
keystone
gomobile
minimagick
combinations
fastboot
pushbullet
infinite-loop
sha
symlink
android-cursorloader
formtastic
overflow
mplab
language-detection
wercker
contextmenustrip
oracle-nosql
webmock
rythm
strategy-pattern
motion
electron-packager
risc
spring-ide
opos
confluent
denodo
multivalue
cancan
visio-2010
node-java
intermediate-language
spring-cloud-aws
was
breadcrumbs
sqlproj
blackberry-webworks
x12
normalisation
laterjs
web-optimization
code-translation
firefox-os
oryx
askbot
magnet-uri
producer-consumer
libgcrypt
musicbrainz
tokudb
nsq
react-os
growl
cocos2d-x-2.x
serializer
image-preloader
cvi
infor-eam
windows-phone-store
facebook-java-api
xrandr
wpd
qmainwindow
pageload
metapost
configurationsection
m3u
motordriver
beep
flatten
bindinglist
jmesa
clgeocoder
wdm
isgl3d
vectorwise
google-local-search
calendarextender

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