Cannot infer MsSql data type from the generic database type ('') / CLR type ('System.Guid') combination given
Hi
I`ve got exception
"Cannot infer MsSql data type from the generic database type ('') / CLR type ('System.Guid') combination given"
Here is my code
public
IQueryable<Document> GetRequestList()
var result = App.WorkWith()
.Documents()
.Where(item => item.Parent.Title == MODULE_TITLE && item.Status == ContentLifecycleStatus.Live)
.OrderByDescending(item => item.DateCreated)
.Get();
Hi Anton,
Thank you for reporting this. Using your error message we identified a missed case in our implementation, but we couldn't think of a way for it to be triggered by our code. We only suspect it is caused by some custom field mapping and if this code is the first thing in your application that accesses (and thus initializes) the libraries provider.
* Do you have some custom fields associated with the "documents" content type?
* If yes, do some of them create a meta field (an artificial field in OpenAccess parlance) of type System.Guid?
* Do you have some custom implementations associated with this?
Yes, there is field of type System.Guid
Here is module code:
using
System;
using
System.IO;
using
System.Linq;
using
System.Net.Mail;
using
System.Net.Mime;
using
System.Web;
using
iTechArt.Modules.ContactUs.Controls;
using
Telerik.Sitefinity;
using
Telerik.Sitefinity.Abstractions;
using
Telerik.Sitefinity.Configuration;
using
Telerik.Sitefinity.GenericContent.Model;
using
Telerik.Sitefinity.Libraries.Model;
using
Telerik.Sitefinity.Model;
using
Telerik.Sitefinity.Modules.Pages.Configuration;
using
Telerik.Sitefinity.Services;
namespace
iTechArt.Modules.ContactUs
public
class
ContactUsModule : ModuleBase
#region Constants
private
const
string
MODULE_TITLE =
"ContactUs"
;
private
const
string
MODULE_URL =
"ContactUs"
;
public
const
string
MODULE_NAME =
"Contact Us"
;
public
const
string
LANDING_PAGE_NAME =
"ContactUs"
;
public
const
string
LANDING_PAGE_TITLE =
"Contact Us"
;
public
const
string
LANDING_PAGE_URL =
"ContactUs"
;
public
const
string
SUB_PAGE_NAME =
"ContactUsList"
;
public
const
string
SUB_PAGE_TITLE =
"Contact Us Requests"
;
public
const
string
SUB_PAGE_URL =
"ContactUsList"
;
public
const
string
REQUEST_TITLE_FORMAT =
"Request For Quote - 0 1 - 2 3"
;
private
readonly
Guid LANDING_PAGE_ID =
new
Guid(
"1166F797-7228-45B1-98D9-02593707BF1A"
);
private
readonly
Guid SUB_PAGE_ID =
new
Guid(
"7E1F6046-DB6E-47C2-9ECF-978540D5A85C"
);
#endregion
public
override
Guid LandingPageId
get
return
LANDING_PAGE_ID;
public
override
Type[] Managers
get
return
null
;
public
override
void
Install(SiteInitializer initializer)
;
/*
bool restart = false;
EnsureMetaFields(ref restart);
using (var sf = App.WorkWith())
int result = 0;
sf.DocumentLibraries().Where(l => l.Title == MODULE_TITLE).Count(out result);
if (result < 1)
sf.DocumentLibrary().CreateNew().Do(lib =>
lib.Title = MODULE_TITLE;
lib.UrlName = MODULE_URL;
);
sf.Page().PageManager.Provider.SuppressSecurityChecks = true;
var moduleNode = sf.Page(SiteInitializer.ModulesNodeId).Get();
var contactUsNode = sf.Pages().Where(p => p.Id == LandingPageId).Get().SingleOrDefault();
if (contactUsNode == null)
// Create landing page
sf.Page().CreateNewPageGroup(moduleNode, LandingPageId).Do(p =>
p.Name = LANDING_PAGE_NAME;
p.ShowInNavigation = true;
p.Attributes["ModuleName"] =
MODULE_NAME;
p.Title = LANDING_PAGE_TITLE;
p.UrlName = LANDING_PAGE_URL;
);
restart = true;
// Create sub page
var subPage = sf.Pages().Where(p => p.Id == SUB_PAGE_ID).Get().SingleOrDefault();
if (subPage == null)
sf.Page().CreateNewStandardPage(LandingPageId, SUB_PAGE_ID).Do(p =>
p.Name = SUB_PAGE_NAME;
p.UrlName = SUB_PAGE_URL;
p.Description =
SUB_PAGE_TITLE;
p.ShowInNavigation = false;
p.Attributes["ModuleName"] =
MODULE_NAME;
).CheckOut()
.Do(
draft =>
draft.TemplateId =
sf.Page().PageManager.GetTemplates().Where(
t => t.Name == SiteInitializer.BackendTemplateName).SingleOrDefault().Id)
.Control().CreateNew(new ContactUsList(), "Content").Done()
.Publish();
restart = true;
if (restart)
SystemManager.RestartApplication(false);
RegisterToolboxControl();
*/
public
IQueryable<Document> GetRequestList()
var result = App.WorkWith()
.Documents()
.Where(item => item.Parent.Title == MODULE_TITLE && item.Status == ContentLifecycleStatus.Live)
.OrderByDescending(item => item.DateCreated)
.Get();
return
result;
public
Document GetRequestById(Guid id)
return
App.WorkWith()
.Documents()
.Where(item => (Guid)item.GetValue(
"QuoteID"
) == id).Get().FirstOrDefault();
/// <summary>
/// Ensures that the Document model has the required metafields.
/// </summary>
/// <param name="restart">if set to <c>true</c> [restart].</param>
private
void
EnsureMetaFields(
ref
bool
restart)
bool
changedDB =
false
;
App.WorkWith().DynamicData().Type(
typeof
(Document))
.Field().TryCreateNew(
"QuoteID"
,
typeof
(Guid),
ref
changedDB).Done()
.Field().TryCreateNew(
"FirstName"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"LastName"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"Company"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"Phone"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"EMail"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"IP"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"Referral"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"Country"
,
typeof
(
string
),
ref
changedDB).Done()
.Field().TryCreateNew(
"Message"
,
typeof
(
string
),
ref
changedDB).SaveChanges(
true
);
if
(changedDB)
restart = changedDB;
protected
override
ConfigSection GetModuleConfig()
return
null
;
public
override
void
Upgrade(SiteInitializer initializer, Version upgradeFrom)
private
void
RegisterToolboxControl()
string
controlType =
typeof
(ContactUsForm).AssemblyQualifiedName;
var conf = Config.Get<ToolboxesConfig>();
var pageControls = conf.Toolboxes[
"PageControls"
];
if
(pageControls.Tools.Values.Count(x => x.Name ==
"ContactUsForm"
) > 0)
return
;
var section = pageControls
.Sections
.Where<ToolboxSection>(e => e.Name ==
"iTechartControlsSection"
)
.FirstOrDefault();
if
(section ==
null
)
section =
new
ToolboxSection(pageControls.Sections)
Name =
"iTechartControlsSection"
,
Title =
"iTechArt Custom Controls"
,
Description =
"iTechArt Custom Controls"
;
pageControls.Sections.Add(section);
section.Tools.Add(
new
ToolboxItem(section.Tools)
ControlType = controlType,
ModuleName = MODULE_NAME,
Name =
"ContactUsForm"
,
Title =
"Contact Us Form"
,
Description =
""
);
Config.GetManager().SaveSection(conf);
public
void
PostRequest(
string
firstName,
string
lastName,
string
company,
string
phone,
string
email,
string
country,
string
message,
string
ip,
string
referralLink,
string
fromEmail,
string
toEmail)
using
(var sf = App.Prepare().SetTransactionName(
"PostRequestTransaction"
).WorkWith())
sf.Documents().GetManager().Provider.SuppressSecurityChecks =
true
;
sf.Document().CreateNew().Do(item =>
item.Parent =
sf.DocumentLibraries().Where(l => l.Title == MODULE_TITLE).Get
().FirstOrDefault();
item.Title =
string
.Format(REQUEST_TITLE_FORMAT,
DateTime.Now.ToLongDateString(),
DateTime.Now.ToLongTimeString(),
firstName, lastName);
item.SetValue(
"QuoteID"
, Guid.NewGuid());
item.SetValue(
"FirstName"
, firstName);
item.SetValue(
"LastName"
, lastName);
item.SetValue(
"Company"
, company);
item.SetValue(
"Phone"
, phone);
item.SetValue(
"Email"
, email);
item.SetValue(
"Country"
, country);
item.SetValue(
"Message"
, message);
item.SetValue(
"IP"
, ip);
item.SetValue(
"Referral"
, referralLink);
).SaveAndContinue().Publish();
SendEmail(firstName, lastName, company, phone, email, country, message, ip, referralLink, fromEmail, toEmail);
private
void
SendEmail(
string
firstName,
string
lastName,
string
company,
string
phone,
string
email,
string
country,
string
message,
string
ip,
string
referralLink,
string
fromEmail,
string
toEmail)
string
htmlMail =
string
.Empty;
string
txtMail =
string
.Empty;
lock
(
this
)
StreamReader streamReader =
File.OpenText(HttpContext.Current.Server.MapPath(
"~/App_Data/EmailTemplates/contactus.html"
));
htmlMail = streamReader.ReadToEnd();
lock
(
this
)
StreamReader streamReader =
File.OpenText(HttpContext.Current.Server.MapPath(
"~/App_Data/EmailTemplates/contactus.txt"
));
txtMail = streamReader.ReadToEnd();
htmlMail = MessageParser(htmlMail, firstName, lastName, company, phone, email, country, message, ip,
referralLink);
txtMail = MessageParser(txtMail, firstName, lastName, company, phone, email, country, message, ip,
referralLink);
MailMessage mailMessage =
new
MailMessage(
new
MailAddress(fromEmail,
"iTechArt Group"
),
new
MailAddress(toEmail));
mailMessage.Subject =
string
.Format(
"Request For Quote from 0 1 2"
, firstName, lastName, company);
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlMail,
null
,
"text/html"
);
//(htmlMail, new ContentType("text/html"));
mailMessage.AlternateViews.Add(htmlView);
AlternateView txtView = AlternateView.CreateAlternateViewFromString(txtMail,
null
,
"text/plain"
);
mailMessage.AlternateViews.Add(txtView);
SmtpClient client =
new
SmtpClient();
client.Send(mailMessage);
private
string
MessageParser(
string
msg,
string
firstName,
string
lastName,
string
company,
string
phone,
string
email,
string
country,
string
message,
string
ip,
string
referralLink)
msg = msg.Replace(
"!QUOTE_TITLE!"
,
string
.Format(
"0 1 2"
, firstName, lastName, company));
msg = msg.Replace(
"!FIRST_NAME!"
, firstName);
msg = msg.Replace(
"!LAST_NAME!"
, lastName);
msg = msg.Replace(
"!COMPANY!"
, company);
msg = msg.Replace(
"!PHONE!"
, phone);
msg = msg.Replace(
"!EMAIL!"
, email);
msg = msg.Replace(
"!COUNTRY!"
, country);
msg = msg.Replace(
"!IP!"
, ip);
msg = msg.Replace(
"!REFERRAL_LINK!"
, referralLink);
msg = msg.Replace(
"!MESSAGE!"
, message);
msg = msg.Replace(
"!CURRENT_DATE!"
, DateTime.Now.ToLongDateString() +
" "
+ DateTime.Now.ToLongTimeString());
return
msg;
Hello Anton,
Thank you for providing this feedback and the relevant code. The code that was not property supported by our infrastructure is actually:
pp.WorkWith().DynamicData().Type(
typeof
(Document))
.Field().TryCreateNew(
"QuoteID"
,
typeof
(Guid),
ref
changedDB).Done()
// ...
.SaveChanges(
true
);